Flash / Flex / ActionScript/Development/MovieClip

Материал из Web эксперт
Перейти к: навигация, поиск

Add frame event listener to MovieClip

   <source lang="java">

package {

    import flash.display.MovieClip;
    import flash.events.Event;
    
    public class Motion extends MovieClip {
         
         public function Motion() {
              trace("Motion class instantiated");
              addEventListener(Event.ENTER_FRAME, update);
         }
         private function updatePosition():void {
              this.x++;
              this.y++;
         }
         private function update(evtObj:Event):void {
              this.updatePosition();
         }
         
    }

}

       </source>
   
  


Change MovieClip position

   <source lang="java">

package {

    import flash.display.MovieClip;
    import flash.events.Event;
    
    public class Motion extends MovieClip {
         
         public function Motion() {
         }
         public function init(xVal:Number,yVal:Number):void {
              this.x = xVal;
              this.y = yVal;
              addEventListener(Event.ENTER_FRAME, update);
         }
         private function updatePosition():void {
              this.x++;
              this.y++;
         }
         private function update(evtObj:Event):void {
              this.updatePosition();
         }
         
    }

}

       </source>
   
  


extends MovieClip

   <source lang="java">

package {

 import flash.display.MovieClip;
 import flash.events.Event;
 public class Motion extends MovieClip {
   
    public function Motion() {
      this.addEventListener(Event.ENTER_FRAME, update);
   }
    
   private function updatePosition():void {
     this. x++;
     this. y++;
   }
   
    private function update(evtObj:Event):void {
     this.updatePosition();
   }
    
 }

}

       </source>
   
  


Variable and Function Definitions in Frame Scripts

   <source lang="java">

package {

 import flash.display.MovieClip;
 import flash.utils.Timer;
 import flash.events.TimerEvent;
 public class Main extends MovieClip {
   private var timer:Timer;
   public function Main() {
     timer = new Timer(100, 0);
     timer.addEventListener(TimerEvent.TIMER, timerListener);
     timer.start(  );
   }
   private function timerListener (e:TimerEvent):void {
     randomFade(  );
   }
   private function randomFade (  ):void {
     alpha = Math.random(  );
   }
   public function dispose (  ):void {
     timer.stop(  );
   }
 }

}

       </source>
   
  


Working with the MovieClip: Using stop() and gotoAndPlay()

   <source lang="java">

package {

   import flash.display.*;
   import flash.net.URLRequest;
   import flash.events.Event;
   
   public class Movies extends Sprite
   {
       public function Movies()
       {
           var loader:Loader = new Loader();
           loader.load(new URLRequest("movie.swf"));
           loader.contentLoaderInfo.addEventListener(Event.ruPLETE, makeMovie);
   
       }
       private function makeMovie(event:Event):void
       {
           var mc:MovieClip = (event.target.content as MovieClip);
           mc.gotoAndPlay("intro");
           mc.addEventListener(Event.ENTER_FRAME, stopMovie);
       }
       private function stopMovie(event:Event):void
       {
           try
           {
               if (MovieClip(event.target).currentFrame == 30)
                   MovieClip(event.target).stop();
           } catch(err:Error) {
               trace("oops...");
           }
       }
   }

}

       </source>