0
votes

I have a number of instances of a movieClip on the stage in Flash. I would like to be able to add a dynamic variable to each. For example, I would like to number each instance.

I have tried giving each instance an instance name (eg. box1, box2) and writing the following code in the layer 1 > frame 1 code window

box1.number = 1;
box2.number = 2; etc.

or

box1["number"] = 1;
box2["number"] = 2;

but the variables are undefined when trying to access them in Flash builder.

1

1 Answers

0
votes

You should create a custom class for all your movieClips to extend (use as a base class). If you don't know how to do this, create the following MyCustomClassName.as file in the root of your .fla directory.

package {

    public class MyCustomClassName extends Sprite {  //use MovieClip is your box makes use of the timeline
        public var myNumber:int = 0;

        public function MyCustomClassName(num:int = 0) {
            myNumber = num;
        }
    }
}

Then on your box object, right click it in the library and bring up the properties/linkage. Set the base class to the path to your custom class .as file

You can leave everything the same and now your boxes will inherit all properties and functions in that base class.

myBoxInstance.myNumber = 5;

OR if instantiating through code:

var box:MyCustomClassName = new MyCustomClassName(5);   //creates a new box giving it the number 5