PDA

View Full Version : Accessing properties of a component in an MC from the Root


snailface
07-02-2007, 07:13 PM
I have a button component "runCalc_button" labeled "Caclulate" within a movie Clip "inputScreen_mc".

I'm trying to access the button's properties from the Root, but I'm getting back "undefined."

Here's my code:

_root.attachMovie("inputScreen_mc", "inputScreen_mc", 200);
trace(_root.inputScreen_mc.runCalc_button);
trace(_root.inputScreen_mc.runCalc_button.label);


the first "trace" returns "_level0.inputScreen_mc.runCalc_button" as it should.
the second returns "undefined."

Anyone know why? Shouldn't it return "Calculate."

snailface
07-02-2007, 07:33 PM
Forgot to mention I am working in MX 2004 :( and ActionScript 2

LOLFlash
07-03-2007, 12:08 AM
when you attach Movie from library flash needs some time to initialize components and their properties
This why you cant access right away label but if you wait a little you could

One of solution: you have to set this properties from within movie in library ether way attach class to move or in first frame in movie in library (first frame starts playing after all contents initialize) add script

var buttonLabel:String;
runCalc_button.label = buttonLabel;

//Call attach in root:
_root.attachMovie("inputScreen_mc", "inputScreen_mc", 200,{ buttonLabel:"My new label"});

Or pass with _root:

_root.myLabel ="new label";
_root.attachMovie("inputScreen_mc", "inputScreen_mc", 200);

//In attached movie should be script:

runCalc_button.label = _root.myLabel;

snailface
07-16-2007, 06:39 PM
Thanks for the help :)