当我期望它时,皮肤类没有被初始化
假设我有一段像这样的代码:
var myPopup:MyPopup = new MyPopup();
myPopup.mainModel = model;
PopUpManager.addPopUp(myPopup,this);
MyPopup
的开头如下所示:
<views:BlaBla
...
skinClass="com.mySkinClass"
...
>
<fx:Script>
<![CDATA[
[SkinPart] public var aButton:Button;
public function set mainModel(mainModel:Something):void {
...
aButton.addEventListener(...);
...
}
mainModel setter 引用在外观中初始化的 aButton 变量。奇怪的是,直到 setter 运行之后,皮肤才被初始化。这会导致空指针异常。我希望皮肤在 var myPopup:MyPopup = new MyPopup();
行中初始化。为什么情况并非如此?有没有办法可以强制皮肤初始化?
Suppose that I have a chunk of code like this:
var myPopup:MyPopup = new MyPopup();
myPopup.mainModel = model;
PopUpManager.addPopUp(myPopup,this);
The beginning of MyPopup
looks like this:
<views:BlaBla
...
skinClass="com.mySkinClass"
...
>
<fx:Script>
<![CDATA[
[SkinPart] public var aButton:Button;
public function set mainModel(mainModel:Something):void {
...
aButton.addEventListener(...);
...
}
The mainModel setter references the aButton variable that is initialized in the skin. Oddly enough the skin is not initialized until after the the setter has run. This causes a null pointer exception. I expect the skin to be initialized in the var myPopup:MyPopup = new MyPopup();
line. Why is this not the case? Is there a way that I can force the skin to be initialized?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答我自己的问题:直到将对象添加到舞台上才创建皮肤。这意味着您必须执行以下操作:
选项 1
或
选项 2
但将对外观中创建的对象的所有引用从 mainModel 的 setter 移至由
creationComplete
触发的方法中。To answer my own question: the skin is not created until until the Object is added to the stage. This means that you either have to do this:
Option 1
or
Option 2
But move all references to objects created in the skin from the setter for mainModel and into a method triggered by
creationComplete
.