Flex编译器错误1120

时间:2012-07-14 23:51:34

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

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

感谢您的时间。

2 个答案:

答案 0 :(得分:2)

您不能在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 :(得分:0)

我弄明白为什么会收到错误。我没有想到并假设我可以在初始化处理程序之外添加一个事件监听器。出于某种原因,我认为AS3将以解释器执行过程脚本的方式运行编译的<fx:Script>标记。

由于某种原因,我没有想到在addedToStage标记中添加<s:Skin>属性,并让它从那里执行positionObjects方法。一切都很好。

相关问题