Archive for December, 2007

Happy New Year

I hope everyone has a safe and happy new year! Keep an eye out for some stuff coming up here shortly.

Tags:

Merry Christmas

Just wanted to wish everyone a very Merry Christmas. Getting everything done here little by little so regular posting should resume shortly. Be patient little ones :P

Tags:

Back From Vacation

Well, I am officially back from Montego Bay, Jamaica (physically, at least) and am trying to catch up on everything I missed this past week. It is looking like I’ll be very busy this week trying to get some rush holiday jobs out the door so I’m not sure how much time I’ll have to post anything. Once the holidays are over, however, definitely look for me to get back into the full swing of things. I apologize for the delays in posts, just a hectic time right now but I’ve got some good stuff planned for the near future so just bare with me. Going to be a very busy time also with trying to close on the house while all this other stuff is happening but we’ll get through it :P

Tags: , ,

AS2: Animating Filters With Fuse

View Example
Download Fuse
Download Example Files

I still use Fuse for my scripted animations in AS2 so I figured I'd show how I animate filters using Fuse in AS2 projects. In this instance, I used the glow filter to animate when you roll over a button. The filter animation in Fuse is pretty much the same no matter what filter you use (of course you have to change the properties of the filter to tween) and you can see all the properties of each tweenable filter in the docs. This is comprised of a class file I made for the button and just some quick code on the timeline to show how to use it.

Here is GlowButton.as:

Actionscript:
  1. import mx.events.EventDispatcher;
  2. import mx.utils.Delegate;
  3. import com.mosesSupposes.fuse.Fuse;
  4. import com.mosesSupposes.fuse.FuseFMP;
  5. import com.mosesSupposes.fuse.PennerEasing;
  6.  
  7. /**
  8. * @author Matt Przybylski [http://www.reintroducing.com]
  9. * @version 1.0
  10. */
  11.  
  12. class com.reintroducing.ui.GlowButton extends MovieClip
  13. {
  14. //- PRIVATE VARIABLES -------------------------------------------------------------------------------------
  15.     
  16.     private var dispatchEvent:Function;
  17.    
  18.     private var _fuse:Fuse;
  19.     private var _id:Number;
  20.     private var _startBlur:Number;
  21.     private var _endBlur:Number;
  22.     private var _active:Boolean;
  23.    
  24. //- PUBLIC VARIABLES --------------------------------------------------------------------------------------
  25.    
  26.     public static var DEFAULT_NAME:String = "com.reintroducing.ui.GlowButton";
  27.    
  28.     public var addEventListener:Function;
  29.     public var removeEventListener:Function;
  30.    
  31.     // instances
  32.     public var title_txt:TextField;
  33.    
  34. //- CONSTRUCTOR -------------------------------------------------------------------------------------------
  35.    
  36.     public function GlowButton()
  37.     {
  38.         super();
  39.        
  40.         EventDispatcher.initialize(this);
  41.        
  42.         this.onLoad = Delegate.create(this, init);
  43.     }
  44.    
  45. //- PRIVATE METHODS ---------------------------------------------------------------------------------------
  46.    
  47.     private function init():Void
  48.     {
  49.         this.initButtonEvents();
  50.     }
  51.    
  52.     /**
  53.      * Adds the events to the button
  54.      */
  55.     private function initButtonEvents():Void
  56.     {
  57.         this.onRollOver = Delegate.create(this, doRollOver);
  58.         this.onRollOut  = Delegate.create(this, doRollOut);
  59.         this.onRelease  = Delegate.create(this, doRelease);
  60.     }
  61.    
  62.     /**
  63.      * Clears the button of events
  64.      */
  65.     private function killButtonEvents():Void
  66.     {
  67.         this.onRollOver = null;
  68.         this.onRollOut  = null;
  69.         this.onRelease  = null;
  70.     }
  71.    
  72.     /**
  73.      * onRollOver
  74.      */
  75.     private function doRollOver():Void
  76.     {
  77.         this._fuse = new Fuse({target: this, Glow_blur: this._endBlur, Glow_alpha: 1, Glow_strength: 2, time: .35, ease: PennerEasing.easeOutSine});
  78.         this._fuse.start();
  79.     }
  80.    
  81.     /**
  82.      * onRollOut
  83.      */
  84.     private function doRollOut():Void
  85.     {
  86.         this._fuse = new Fuse({target: this, Glow_blur: this._startBlur, Glow_alpha: .5, Glow_strength: 2, time: .35, ease: PennerEasing.easeOutSine});
  87.         this._fuse.start();
  88.     }
  89.    
  90.     /**
  91.      * onRelease
  92.      */
  93.     private function doRelease():Void
  94.     {
  95.         this.dispatchEvent({type: "onGlowButtonClicked", target: this});
  96.     }
  97.    
  98. //- PUBLIC METHODS ----------------------------------------------------------------------------------------
  99.    
  100.     /**
  101.      * Sets the properties of the button
  102.      */
  103.     public function create($title:String, $id:Number, $color:Number, $startBlur:Number, $endBlur:Number):Void
  104.     {
  105.         this.title_txt.text = $title;
  106.         this._id = $id;
  107.         this._startBlur = $startBlur;
  108.         this._endBlur = $endBlur;
  109.        
  110.         FuseFMP.writeFilter(this, "Glow", {color: $color, blur: this._startBlur, alpha: .5, strength: 2});
  111.     }
  112.    
  113.     /**
  114.      * Enables the button
  115.      */
  116.     public function setEnabled():Void
  117.     {
  118.         this.initButtonEvents();
  119.        
  120.         this.enabled = true;
  121.         this._active = true;
  122.        
  123.         this._fuse = new Fuse({target: this, alpha: 100, Glow_blur: this._startBlur, Glow_alpha: .5, Glow_strength: 2, time: .35, ease: PennerEasing.easeOutSine});
  124.         this._fuse.start();
  125.     }
  126.    
  127.     /**
  128.      * Disables the button
  129.      */
  130.     public function setDisabled():Void
  131.     {
  132.         this.killButtonEvents();
  133.        
  134.         this.enabled = false;
  135.         this._active = false;
  136.        
  137.         this._fuse = new Fuse({target: this, alpha: 50, Glow_blur: 0, Glow_alpha: 0, Glow_strength: 0, time: .35, ease: PennerEasing.easeOutSine});
  138.         this._fuse.start();
  139.     }
  140.    
  141. //- EVENT HANDLERS ----------------------------------------------------------------------------------------
  142.    
  143.    
  144.    
  145. //- GETTERS & SETTERS -------------------------------------------------------------------------------------
  146.    
  147.     public function get id():Number
  148.     {
  149.         return this._id;
  150.     }
  151.    
  152.     public function set id($val:Number):Void
  153.     {
  154.         this._id = $val;
  155.     }
  156.    
  157.     public function get active():Boolean
  158.     {
  159.         return this._active;
  160.     }
  161.    
  162.     public function set active($val:Boolean):Void
  163.     {
  164.         this._active = $val;
  165.     }
  166.    
  167. //- HELPERS -----------------------------------------------------------------------------------------------
  168.    
  169.     public function toString():String
  170.     {
  171.         return "com.reintroducing.ui.GlowButton";
  172.     }
  173.    
  174. //- END CLASS ---------------------------------------------------------------------------------------------
  175. }

And here is the code on the timeline which just sets up the buttons:

Actionscript:
  1. import com.reintroducing.ui.GlowButton;
  2. import com.mosesSupposes.fuse.*;
  3.  
  4. ZigoEngine.register(Fuse, FuseFMP, PennerEasing);
  5.  
  6. var numButtons:Number = 4;
  7.  
  8. function setButtons():Void
  9. {
  10.     var btn:GlowButton;
  11.    
  12.     for (var i:Number = 0; i <numButtons; i++)
  13.     {
  14.         btn = GlowButton(this["btn" + i + "_mc"]);
  15.         btn.create("button" + i, i, 0x996600, 5, 10);
  16.         btn.addEventListener("onGlowButtonClicked", this);
  17.     }
  18. }
  19.  
  20. function onGlowButtonClicked($evt:Object):Void
  21. {
  22.     for (var i:Number = 0; i <numButtons; i++)
  23.     {
  24.         var btn:GlowButton = GlowButton(this["btn" + i + "_mc"]);
  25.        
  26.         if (btn.active == false)
  27.         {
  28.            
  29.             btn.setEnabled();
  30.         }
  31.     }
  32.    
  33.     $evt.target.setDisabled();
  34. }
  35.  
  36. setButtons();

I'm quite aware this isn't the prettiest example (as my examples usually are on the ugly side), but it's the code that counts here :P

Tags: , , ,