Ultrashock Forums > Flash > ActionScript
AS3 - Is this correct?

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS3 - Is this correct?
Old 2009-11-10

This post is a culmination of many answers combined together. So I want to make sure I understand.

In order to add an mc to the stage from the library, you refer to it by its name in the library. The way all of this is done is:
Code:
var someMc:String = "this_mc";
newClass = getDefinitionByName(someMc);
mcAdded= new newClass ();
addChild(mcAdded);
If I wanted to name the mcAdded before its added to the stage would I then use "mcAdded.name = someName" before the addChild?

Here is where things have always been fuzzy. If I wanted to edit the mcAdded after it's been added to stage, I would:
Code:
var someString:String = "mcAdded";
var selectedInstance = getChildByName( someString);

selectedInstance.x = 210;
I've had problems with accessing the instances on the stage in the past. It seems the names of MCs I add to the stage via code are usually messed up. Sometimes their called something like "instance 47". Sometimes [object mcAdded]. How do I fix this so I can guarantee that the names of all future instances are predictable? Is there a better way to handle all of this?
postbit arrow 1 comment | 101 views postbit arrow Reply: with Quote   
Registered User
BSMH is offline
seperator
Posts: 196
2004-07-29
BSMH lives in United States
seperator

Ultrashock Member Comments:
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2009-11-10 #2 Old  
If your working from the timeline and want to add a mc from the library to the stage just give it a class name and instantiate it.

Code:
// Mc in library has a class name of Foo and exported on the first frame

var f:Foo = new Foo();
f.name = "foo is my name";
addChild(f);
trace(f.name);
A couple of times working in AS2 I would receive names like instance47 and some other weird names. I usually just re-start Flash and it seems to work fine.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: