as3 can't set checkbox label - need to know when it is loaded

家住魔仙堡 提交于 2019-12-24 19:17:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!