我知道网上有关于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>

感谢您的时间。

最佳答案

您不能在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>

关于actionscript-3 - Flex编译器错误1120,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11488274/

10-09 04:14