Hi all,
Just a behavior that is perplexing and maybe someone could shed a
light to the true core of the matter. I have a PopUpButton which on
itemClick changes to a different state, the following is thrown:
Error #1009: Cannot access a property or method of a null object
reference
I debugged and realised that this is down to the fact that the
PopUpButton is actually not present in the new state, the null object
is thrown when the PopUpButton Class tries to reference the _popUp
instance. So the instance is not present in the new state but why
should that be throwing an error? A closer look seemed to reveal that
when I click the PopUpButton it runs my declared method and also fires
a close event that results in running a method displayPopUp to show/
hide the popup menu, I guess timing is an issue here cos obviously
that popup is no longer there for it to hide ( the point here the
error is thrown - Line 772).
My way around this is to use the callLater() method for changing the
state and this solves it fine. However, I am unsure if this should be
an issue in the first place. Has anyone else discovered issues with
navigation and states and is this an expected behavior?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" creationComplete="initApp();">
<mx:states>
<mx:State name="newtriks">
<mx:RemoveChild target="{p_one}"/>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.events.MenuEvent;
import mx.controls.Menu;
import mx.collections.ArrayCollection;
private var p_one_data:ArrayCollection;
private var s_menu:Menu;
private function initApp():void
{
p_one_data = new ArrayCollection([
{label: "One", data: "one"},
{label: "Two", data: "two"},
{label: "Three", data: "three"}
]);
s_menu = new Menu();
s_menu.dataProvider = p_one_data;
s_menu.addEventListener( MenuEvent.ITEM_CLICK,
siteHandler );
p_one.popUp = s_menu;
}
/**
* Causes a problem
*/
private function siteHandler( e:MenuEvent ):void
{
this.currentState = 'newtriks';
}
/**
* Work around
private function siteHandler( e:MenuEvent ):void
{
callLater( changeMyState, ['newtriks'] );
}
private function changeMyState( where:String ):void
{
this.currentState = 'newtriks';
}
*/
]]>
</mx:Script>
<mx:PopUpButton id="p_one" label="p_one"/>
</mx:Application>
Cheers,
Simon