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开发者_JAVA技巧 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!
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.
精彩评论