[unsolved] AS3: How to declare instance names?

Subscribe to [unsolved] AS3: How to declare instance names? 4 posts

Sign in to reply


 
avatar for BrainStormer BrainStormer 386 posts
Flag Post

Hi.

Say I make a symbol, place it in Root.main.content, and set its instance name to contentBg. Now how do I declare that instance in my code? As a result I want to be able to do for example this:

Root.main.content.contentBg.x = 100;

In AS2 I didn’t have to do any special declarations, but here I have to and don’t know how :)

Thanx!

 
avatar for the8bitYoda the8bitYoda 79 posts
Flag Post

What exactly is Root.main.content? Is that a package? or are they also symbols?

 
avatar for CuriousGaming CuriousGaming 394 posts
Flag Post

So, you’ve created a movieclip in the library, and checked the ‘export for actionscript’ button in the properties, right?

Suppose you called the movieClip in the library ‘Stickman’

myNewStickman : Stickman = new Stickman();
stage.addChild(myNewStickman);

You can now reference that movieclip by

myNewStickman.x = 100;

No need to use root at all. AS3 doesn’t really use root anymore.

If you’ve already dragged a copy of the movieclip onto the stage you can give it a name in the properties window. You don’t ned to declare it in that case. Whatever name you gave it, that’s what you use in your actionscript to reference that movieclip.

 
avatar for UnknownGuardian UnknownGuardian 6248 posts
Flag Post

In AS3, you should hardly ever need to use instance names, since usually they are referenced by variables. If you feel that you need to use the reference name of the object, you can find it by the objects name property.

var myNewStickman : Stickman = new Stickman();
myNewStickman.name = "bob";   //I believe its a string, but not positive.

Sign in to reply