Flash basic Theory Class chapter II ActionScript 3.0 Animation Foundation Ⅱ

Source: Internet
Author: User

Back to "flash Basic Theory Class-Catalog"

Animation events

We want to be able to use code to make things move and allow the screen to refresh repeatedly. I've seen an example of using the Enterframe movie event earlier. Now apply this method to as 3, just add a listener to the Enterframe event:

addEventListener(Event.ENTER_FRAME, onEnterFrame);

Don't forget to import the Event class and create a method named Onenterframe. People often confuse, only one frame how can execute Enterframe (enter frame) event? In fact, the playhead is not really in the next frame, it only stays on the first frame, not to move the playhead to the next frame to form the Enterframe event, but in another way: Flash tells the player when to move, you can see Enterframe as a timer, Just a little imprecise.

Now let's take a look at the first as 3 animation:

package {
 import flash.display.Sprite;
 import flash.events.Event;
 public class FirstAnimation extends Sprite {
  private var ball:Sprite;
  public function FirstAnimation() {
   init();
  }
  private function init():void {
   ball = new Sprite();
   addChild(ball);
   ball.graphics.beginFill(0xff0000);
   ball.graphics.drawCircle(0, 0, 40);
   ball.graphics.endFill();
   ball.x = 20;
   ball.y = stage.stageHeight / 2;
   ball.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
  private function onEnterFrame(event:Event):void {
   ball.x++;
  }
 }
}

The init function creates an sprite movie named Ball and establishes an event listener for it. The Onenterframe function is responsible for ball movement and screen refresh work. This is the basis for learning the content of this book, but also the basis for creating animations using ActionScript, so be sure to master it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.