News on Twitter

AS3 Code for Frame Management

As asked for here’s the code for managing frame animations:

stop(); //stops the movie on the first frame
box1.addEventListener(MouseEvent.CLICK, goToPage1);
function goToPage1(event:MouseEvent):void {
gotoAndStop(“page1″);
}

In addition, you might try adding a circle movieclip to the stage in the first frame of the main timeline. Give the circle an instance name of circle.

Then supply some code in an actions layer on the first frame:

circle.x = 10;
circle.y = 20;

var speed:Number = 10;
var rightWall:Number = 400;

addEventListener(Event.ENTER_FRAME, goCircle);

function goCircle(event:Event):void {
circle.x += speed;
if(circle.x > rightWall) {
circle.x = rightWall;
speed = 0;
removeEventListener(Event.ENTER_FRAME, goCircle);
}
}

The above examples illustrate a mouse event and a frame event.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>