【问题标题】:Flex Compiler Error 1120Flex 编译器错误 1120
【发布时间】:2012-07-14 23:51:34
【问题描述】:

我知道网上有一百万个关于 AS3 编译器错误1120: Access of undefined property <property> 的问题,但这种情况很奇怪。

我正在为 Flex 4.6 中的 <s:Application> 组件蒙皮,并且我在蒙皮 MXML 文件中。 super.addEventListener(Event.ADDED_TO_STAGE, positionObjects); 这行给我的问题是:1120: Access of undefined property positionObjects。然而positionObjects 被声明在它的正下方。知道有什么问题吗?

<fx:Script>
    <![CDATA[
        /**
         *  @private
         */
        override protected function updateDisplayList(unscaledWidth:Number, 
            unscaledHeight:Number) : void
        {
            bgRectFill.color = getStyle('backgroundColor');
            bgRectFill.alpha = getStyle('backgroundAlpha');
            super.updateDisplayList(unscaledWidth, unscaledHeight);
        }

    //Listen for when objects are added to the stage, before positioning them
        [Bindable]
        private var logoX:Number = 0;

        super.addEventListener(Event.ADDED_TO_STAGE, positionObjects);

        private function positionObjects(e:Event):void {
            this.logoX = stage.stageWidth / 3;
        }
    ]]>
</fx:Script>

感谢您的宝贵时间。

【问题讨论】:

    标签: actionscript-3 flash apache-flex flex4 compiler-errors


    【解决方案1】:

    您不能在 fx:Script 块中执行可执行的实现,例如:

    <fx:Script>
        super.addEventListener(Event.ADDED_TO_STAGE, positionObjects);
    </fx:Script>
    

    这应该从生命周期函数中调用,例如创建完成:

    <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
            alpha.disabled="0.5"
            alpha.disabledWithControlBar="0.5"
            creationComplete="skin1_creationCompleteHandler(event)">
    
        <fx:Script fb:purpose="styling">
            <![CDATA[
    
                /* your implementation, same as before... */
    
                protected function skin1_creationCompleteHandler(event:FlexEvent):void
                {
                    // move your event listener to this function.
                    super.addEventListener(Event.ADDED_TO_STAGE, positionObjects);
                }
            ]]>
        </fx:Script>
    </s:Skin>
    

    【讨论】:

    • 好的,谢谢。几秒钟前我刚刚回答了我自己的问题。 +1
    【解决方案2】:

    我知道为什么会出错。我没有考虑并假设我可以在初始化处理程序之外添加一个事件侦听器。出于某种原因,我认为 AS3 会像解释器执行程序脚本一样通过编译的 &lt;fx:Script&gt; 标签运行。

    出于某种原因,我再一次没有想到将addedToStage 属性添加到&lt;s:Skin&gt; 标记,并让它从那里执行positionObjects 方法。现在一切都很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 2020-09-03
      相关资源
      最近更新 更多