问题
We have a fla, and under "Advanced Actionscript Settings", we have
"Automatically declare stage instances"
UNchecked.
We then have a bunch of these declarations at the class level of our document class:
public var spouseCheck:CheckBox;
If I set spouseCheck.label = "blah" in my constructor, it does not work. However, if I set it later, (when another event happens), it does work. This implies that the checkbox is completely loaded at that time. How can I put an event listener on the checkbox so that I will know when it is completely loaded, and I can set the label? thanks!
回答1:
In the constructor of the class where you set spouseCheck.label = "blah"
, remove that line and add this line:
spouseCheck.addEventListener(Event.ADDED_TO_STAGE,init);
Then create the init function:
function init(e:Event):void {
spouseCheck.label = "blah";
spouseCheck.removeEventListener(Event.ADDED_TO_STAGE,init);
}
That event is triggered when spouseCheck is on the displayList (stage) and should ensure it's ready.
来源:https://stackoverflow.com/questions/12504345/as3-cant-set-checkbox-label-need-to-know-when-it-is-loaded