flex – loaderInfo null在creationComplete处理函数中
发布时间:2020-12-15 01:48:49 所属栏目:百科 来源:网络整理
导读:我编写了这个小片段,以显示我不理解的内容: ?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.
我编写了这个小片段,以显示我不理解的内容:
<?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:LucasflexAppNamesrcTeste.mxml:5] at Teste/___Teste_Application1_creationComplete()[C:UserflexCornetaRecordersrcTeste.mxml:2] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreUIComponent.as:9298] at mx.core::UIComponent/set initialized()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreUIComponent.as:1169] at mx.managers::LayoutManager/doPhasedInstantiation()[C:autobuild3.2.0frameworksprojectsframeworksrcmxmanagersLayoutManager.as:718] at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/callLaterDispatcher2()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreUIComponent.as:8628] at mx.core::UIComponent/callLaterDispatcher()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreUIComponent.as:8568] 我不应该能够在creationComplete处理程序中读取loaderInfo吗?我正在尝试将字符串从html传递到我的flash组件,这就是为什么我必须让loaderInfo工作. 解决方法
在FlexEvent.APPLICATION_COMPLETE事件触发之前,loaderInfo对象不可用.尝试将代码更改为:
<?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. 希望有所帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |