tags:

views:

175

answers:

3

I am using Flex 4, I have a main application like this;

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:ModuleLoader id="ml1"  url="ModuleOne.swf"  />
</s:Application>

And ModuleOne.mxml is;

   <?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300" creationComplete="module1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;

            protected function module1_creationCompleteHandler(event:FlexEvent):void
            {
                Alert.show("Alert");
            }

        ]]>
    </fx:Script>
</mx:Module>

When I run the main application I get the following error concerning creationComplete action;

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.managers::PopUpManagerImpl/http://www.adobe.com/2006/flex/mx/internal::createModalWindow()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\PopUpManagerImpl.as:682]
    at mx.managers::PopUpManagerImpl/addPopUp()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\PopUpManagerImpl.as:397]
    at mx.managers::PopUpManager$/addPopUp()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\PopUpManager.as:193]
    at mx.controls::Alert$/show()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\controls\Alert.as:618]
    at ModuleOne/module1_creationCompleteHandler()[E:\src\ModuleOne.mxml:12]
    at ModuleOne/___ModuleOne_Module1_creationComplete()[E:\src\ModuleOne.mxml:4]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
    at mx.core::UIComponent/set initialized()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1577]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]

is there a reason why I cannot have creationComplete in modules? am I doing something wrong?

A: 

I think that creationComplete() is called on child objects before being fired on the parent. Since you specify the url of your moduleLoader right in the MXML, it's probably getting loaded before the application is ready to display PopUps. I would suggest trying the following:

  • leave the URL out of the MXML, but add a creationComplete() handler on your application that does ml1.url = "ModuleOne.swf";
  • try the updateComplete event instead?

Sorry for the non-specific solution, but at least it's clear where your problem is...

Kelsey Rider
+1  A: 

The creationComplete event may or may not be fired on children before the parent. It depends on the creationPolicy flag of the parent. If it is set to "all", then it makes sure to create all children before firing off its own creationComplete. Otherwise, it is not required to do so, which is how it implements delayed initialization.

See:

http://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=containers_intro_063_12.html

and

http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_05.html

eruciform
A: 

Hi,

I am also facing the same issue. It is not related to creationComplete at all. Wherever I write Alert.show() inside a module I get the exact error as mentioned in the original post.

I have even tried with a module which only has a button and on click event of the button I am doing Alert.show("message").

A simplest of the Alert is not working for me. Please help.

Thanks Deep

Deep