NAVIGATION:

 

SUPPORTERS:

FlashComponents
  Flash Templates
  Flash Gallery
  Flash Slideshow
  Flash Menu
  Flash Design
  Flash Video
  User Interface

  

FOLLOW:

RSS it down! Twitter it up! Facebook it like a fiend!

 

 

 

 

 

 
Springs
in MX: Making the Prototype Work
         written by ilyas usal a.k.a. pom

In the first tutorial concerning springs, there was a problem when I was trying to apply the prototype move to several objects. It worked with Flash 5, but not with MX, where all the objects had the same motion, as if Flash had grouped them into one big object. Well, I did my little research, and it turns out that Flash MX handles variables quite differently from Flash 5.

Making It Work
The prototype should look like this:


 

Basically, I put this. in front of all the variables. Explanation :

Writing the prototype the way I had (without the this.) makes the variables relative to the timeline containing the definition of the prototype. This means that all the movie clips will share these variables, and consequently the same behavior. Another risk would be that the variables overwrite variables from that timeline if they have the same name.

Putting this. in front of the variables makes them relative to the object that calls the function, that is to say the movie clip in the present situation.

How Flash Handles Variables
If you try this code in the main timeline:

function move(){
x++;
};

Then when you use this function, you create or modify a variable in the main timeline.

If you turn it into :

function move(){
var x;
x++;
};

A variable is created in the variable space of the function, and it will be destroyed when you get out of the function.

And if we write in the main timeline :

MovieClip.prototype.myFunction=function() { x++;}

Flash looks for x in the main timeline, where the function has been defined, no matter from which timeline is called the function.

Now with this :
 

function move(){
this.x++;
}

x belongs to the object calling the function (this refers to the object possessing the function as a method).
This means that if we use this function as a method :
 

MovieClip.prototype.move=move;

this will point to the movie clip calling its method move.

To summarize a little bit
When the ActionScript interpreter sees a reference to a variable in a method/function, it checks first if it is defined INSIDE the function (with var), then in the timeline where the function/method has been defined. Using this, we tell Flash not to look at the variables of the function/method nor in the timeline containing the definition of the function, but rather in the object to which the method/function belongs.

This article is written by Ilyas Usal. Ilyas is also known as ilyaslamasse on the kirupa.com forums! If you have any questions, please post them on the forums by clicking here.

 
pom 0]

 

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Flipping Book - page flip flash component. Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery
Everythingfla - HD video school membership starts as low as 4.99 a month for the first 3 months. New Videos  updated weekly. current focus is Learning how to develop in AS3. Simple Client Review System
tweenFx - point and click animation Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)