apache-flex - loaderInfo null 在 creationComplete 处理程序函数中

标签 apache-flex actionscript

我编写了这个小片段以显示我不理解的内容:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
    public function init():void {
        txtName.text = this.loaderInfo.toString();
    }
    </mx:Script>
    <mx:TextInput x="50" y="10" id="txtName"/>
</mx:Application>

我收到以下错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Teste/init()[C:\Lucas\flex\AppName\src\Teste.mxml:5]
    at Teste/___Teste_Application1_creationComplete()[C:\User\flex\CornetaRecorder\src\Teste.mxml:2]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
    at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169]
    at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
    at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]

我不应该能够在 creationComplete 处理程序中读取 loaderInfo 吗?我试图将一个字符串从 html 传递到我的 flash 组件,这就是我必须让 loaderInfo 工作的原因。

最佳答案

loaderInfo 对象在 FlexEvent.APPLICATION_COMPLETE 事件触发之前不可用。尝试将您的代码更改为:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
    <mx:Script>
    <![CDATA[
        public function init():void {
            txtName.text = this.loaderInfo.toString();
        }
    ]]>
    </mx:Script>
    <mx:TextInput x="50" y="10" id="txtName"/>
</mx:Application>

请注意,第 2 行 creationComplete 已更改为 applicationComplete

希望有帮助!

关于apache-flex - loaderInfo null 在 creationComplete 处理程序函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747015/

相关文章:

actionscript - 将其他 Haarcascade xml 与 Marilena 一起使用

actionscript-3 - AS3 类扩展 Sprite

flash - 将富文本粘贴到 Flash 中?

apache-flex - 将 CURL 转换为 FLEX HTTP 请求

apache-flex - 用不确定的微调器替换 Flex 预加载器杆?

apache-flex - 是否可以在 Flex3 网站上使用 Google Adsense?

flash - Pixel Bender 访问 iOS API?

java - 如何从 Eclipse 插件提供 Flash 策略文件?

arrays - AS3 :removing every elements in an array at once using for loop

flash - 如何在 Actionscript 3.0 中使用静态函数?