Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 QuickSkills
Controlling Actionscript I  

Actionscript inside a movieclip


Download this .fla
  onClipEvent(enterFrame){
this._x += 10;
this._y += 20;
}

This code is executed once every time the animation enters a new frame. As you can see the ball leaves the stage and moves out of view. But by looking at the Actionscript we can see that flash is still rendering the animation even though we cannot see it.If you were to put a trace() inside the function you will see in the output panel that the code will run as long as the swf is open  (potentially forever).

More onClipEvent (enterframe) examples
 

Download this .fla
  onClipEvent(mouseMove){
this._x += 2;
this._y += 2;
}

This code is executed every time the mouse is moved on the stage. So if the mouse does not move the code is not executed and the ball does not move.

More onclipevent (mouseMove) examples
 

Download this .fla
  onClipEvent(mouseMove){
for(i=0;i<5;i++){
this._x += 2;
this._y += 1;
}
}

Every time the mouse is moved the a section of code is looped.This loop repeats the code inside it five times.Since the code inside is adding a number to the x and y coordinate every time the mouse is moved the x moves by 5 pixels and the y coordinate moves by 10 pixels.

Actionscript on the main timeline


Download this .fla
  for(i=0;i<200;i++){
_root.mc1._x += 2;
_root.mc1._y += 1;
updateAfterEvent();
}

This main timeline code performs operation of adding values to the x and y co-ordinates 100 times. It is called and run automatically independently of the frame rate.The animation occurs as fast as the computer's processor will allow moving 200 steps and then stopping. It happens so fast that all you see is the final position of the object with the animation.

© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us