views:

33

answers:

1

I am a little confused. I made a button symbol and I put a textbox called "butLabel". this button is encapsulated into another movieclip called MainMenu. cbegin is the instance name I gave the button. If I trace like this....

trace(menu.cbegin);

It recognizes cbegin is a button. but if I trace it like this

trace(menu.cbegin.butLabel);

it says butLabel is null. Below is how I call on the Menu movieclip

var menu = new MainMenu();
trace(menu.cbegin.butLabel);
menu.x = sr.stageWidth/2;
menu.y = sr.stageHeight/2;

Again, the button works, but the label inside of the button doesnt. textfield is set to dynamic and I copied and pasted the name that was in the instance name field, into my code. so they have to be the same. I also went about typing the word button into the text field by default from the library, and it seems to work fine but if I alter the textfield via code, it doesn't work. Any suggestions as of what is going on ?? Thanks!

+1  A: 

Here is what you can do, it is sort of hackish.

NOTE: This assumes the TextField is on the 2nd layer (ie. getChildAt(1)), above the initial layer created when you make a SimpleButton.

var menu:MainMenu = new MainMenu();
addChild(menu);

var upStateContainer:DisplayObjectContainer = menu.cbegin.upState as DisplayObjectContainer;
var butLableUp:TextField = upStateContainer.getChildAt(1) as TextField;
butLableUp.text = "Up State";

or as a one liner:

((menu.cbegin.upState as DisplayObjectContainer).getChildAt(1) as TextField).text = "UP State";

Explanation: When flash is compiled from the Flash IDE, all instances of SimpleButton, and their children, are converted to their base display types, like Sprites. Even if you have one textfield on a layer over the button states that spans all four frames, there will be a textfield generated for each of the 3 visible button states. The instance name of the textfield doesn't even matter and is never used.

sberry2A
I don't exactly understand what you said But it works! What it seems your saying is that during compile time, all containing objects of simpleButton objects turn into displayObjectContainers. Which are display objects that are pretty much duds (i.e. lightweight empty display objects). therefore it loses its properties such as text. therefore that is why it didnt work. we just took and casted the object back to a textfield ? Is this only for SimpleButtons ?? and Thanks Alot!
numerical25