actionscript-3 - Flex编译器错误1120

标签 actionscript-3 flash apache-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>

感谢您的时间。

最佳答案

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

相关文章:

javascript - 如何在 Javascript 中创建自定义事件类?

image - Action 3。在mp3可用或不可用时显示替代图像(使用条件图像)

flash - 如何确定关联数组是否有键?

java - 在已经使用 spring-mvc 作为依赖项的依赖项的应用程序中设置 spring-mvc

java - 在没有 FileReference 的 Flex 中上传

flash - Actionscript 3 - 完全移除一个 child

flash - 等价于 as3 中的 md5(uniqid(mt_rand()))?

php - 如何从php和mysql制作xml文件

apache-flex - 生成 ASDoc 的问题

apache-flex - Adobe Flex - 单击按钮时显示自定义工具提示