home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / DSS145 / DSS145_07 / DSS145_07.swf / scripts / dss145_07 / FadeOut.as < prev    next >
Text File  |  2012-07-18  |  1KB  |  55 lines

  1. package dss145_07
  2. {
  3.    import flash.display.DisplayObjectContainer;
  4.    import flash.display.Sprite;
  5.    import flash.events.Event;
  6.    
  7.    public class FadeOut extends Sprite
  8.    {
  9.        
  10.       
  11.       public var color:Number = 0;
  12.       
  13.       public var speed:Number = 0.1;
  14.       
  15.       private var _callback:Function = null;
  16.       
  17.       public function FadeOut(param1:DisplayObjectContainer, param2:Function = null)
  18.       {
  19.          super();
  20.          param1.addChild(this);
  21.          this._callback = param2;
  22.          this.init();
  23.       }
  24.       
  25.       private function init() : void
  26.       {
  27.          graphics.beginFill(this.color,1);
  28.          graphics.drawRect(0,0,800,600);
  29.          graphics.endFill();
  30.       }
  31.       
  32.       public function start() : void
  33.       {
  34.          alpha = 1;
  35.          stage.addEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
  36.       }
  37.       
  38.       private function enterFrameHandler(param1:Event) : void
  39.       {
  40.          alpha -= this.speed;
  41.          if(alpha <= 0)
  42.          {
  43.             this.finish();
  44.          }
  45.       }
  46.       
  47.       public function finish() : void
  48.       {
  49.          stage.removeEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
  50.          parent.removeChild(this);
  51.          this._callback();
  52.       }
  53.    }
  54. }
  55.