I need some help with an error I am getting when using the popupmanager.
Essentially the problem I am having is if I dynamically load SWFs from
my main application and more than one of the SWF uses the popupmanager I
receive an error. The specific error I am getting is:
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at mx.managers::PopUpManager$/addPopUp()
at mx.controls::Alert$/show()
at Tab2/::onClick()
at Tab2/___Button1_click()
My test app to reproduce this problem is essentially on the main
application a tabnavigator with two VBox as the tabs. The SWF files then
get loaded dynamically into those VBox. The two SWF files only contain a
button to press and it displays an Alert (the builtin Alert uses
PopUpManager).
Has anyone seen this error before and can shed some insight?
Thanks in advance.
--Mark
Below is my code to reproduce this:
PopUpApp.as
package
{
import mx.core.Application;
import flash.events.Event;
public class PopUpApp extends Application
{
[Bindable] public var debug:Boolean;
public function PopUpApp()
{
super(); //Invoke the Application superclass
this.addEventListener("creationComplete",
onCreationComplete);
}
private function onCreationComplete(event:Event):void
{
debug = (this.url.indexOf("-debug.swf")) > -1 ? true :
false;
}
}
}
PopUpProblem.mxml
<?xml version="1.0" encoding="utf-8"?>
<local:PopUpApp
xmlns:local="*"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="100%"
height="100%"
creationComplete="onCreationComplete();">
<mx:Script>
<![CDATA[
import mx.events.ModuleEvent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
public var tab1Mod:IModuleInfo;
public var tab2Mod:IModuleInfo;
private function onCreationComplete():void
{
if (this.debug)
{
tab1Mod = ModuleManager.getModule("Tab1-debug.swf");
tab2Mod = ModuleManager.getModule("Tab2-debug.swf");
}
else
{
tab1Mod = ModuleManager.getModule("Tab1.swf");
tab2Mod = ModuleManager.getModule("Tab2.swf");
}
tab1Mod.addEventListener(ModuleEvent.READY,
tab1ModReady);
tab2Mod.addEventListener(ModuleEvent.READY,
tab2ModReady);
tab1Mod.load();
tab2Mod.load();
}
private function tab1ModReady(event:ModuleEvent):void
{
tab1.addChild(tab1Mod.factory.create() as
DisplayObject);
}
private function tab2ModReady(event:ModuleEvent):void
{
tab2.addChild(tab2Mod.factory.create() as
DisplayObject);
}
]]>
</mx:Script>
<mx:TabNavigator width="100%" height="100%">
<mx:VBox id="tab1" label="Tab 1" width="100%" height="100%" />
<mx:VBox id="tab2" label="Tab 2" width="100%" height="100%" />
</mx:TabNavigator>
</local:PopUpApp>
Tab1.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
percentWidth="100"
percentHeight="100">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
private function onClick(event:MouseEvent):void
{
mx.controls.Alert.show("Tab1 Alert");
}
]]>
</mx:Script>
<mx:Button label="Button" click="onClick(event);"/>
</mx:Module>
Tab2.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
percentWidth="100"
percentHeight="100">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
private function onClick(event:MouseEvent):void
{
mx.controls.Alert.show("Tab2 Alert");
}
]]>
</mx:Script>
<mx:Button label="Button" click="onClick(event);"/>
</mx:Module>