当我期望它时,皮肤类没有被初始化

发布于 2024-12-13 16:43:46 字数 753 浏览 1 评论 0原文

假设我有一段像这样的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁轨上的流浪者 2024-12-20 16:43:46

回答我自己的问题:直到将对象添加到舞台上才创建皮肤。这意味着您必须执行以下操作:

选项 1

var myPopup:MyPopup = new MyPopup();    
PopUpManager.addPopUp(myPopup,this);  
myPopup.mainModel = model;  

选项 2

var myPopup:MyPopup = new MyPopup();  
myPopup.mainModel = model;   
PopUpManager.addPopUp(myPopup,this);  

但将对外观中创建的对象的所有引用从 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

var myPopup:MyPopup = new MyPopup();    
PopUpManager.addPopUp(myPopup,this);  
myPopup.mainModel = model;  

or

Option 2

var myPopup:MyPopup = new MyPopup();  
myPopup.mainModel = model;   
PopUpManager.addPopUp(myPopup,this);  

But move all references to objects created in the skin from the setter for mainModel and into a method triggered by creationComplete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文