Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loaderInfo null inside creationComplete handler function

I've coded this small snippet to show what I'm not understanding:

<?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>

I'm getting the following error:

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]

Shouldn't I be able to read loaderInfo inside the creationComplete handler? I'm trying to pass a string from the html to my flash component, that's why I have to get loaderInfo working.

like image 594
Thiago Avatar asked Dec 18 '22 01:12

Thiago


1 Answers

The loaderInfo object isn't available until the FlexEvent.APPLICATION_COMPLETE event fires. Try changing your code to this:

<?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>

Notice on line 2 that creationComplete was changed to applicationComplete.

Hope that helps!

like image 168
RJ Regenold Avatar answered Dec 26 '22 15:12

RJ Regenold