Suppose you use States to display a system message which you have in a separate MXML component like this:

 

<mx:State name="systemMessageVisible">

<mx:AddChild target="{this}" position="firstChild">

            <mycomponents:SystemMessageDialog id="TheSystemMessageDialog" okay="onSystemMessageOk(event)"/>

</mx:AddChild>

</mx:State>

 

SystemMessageDialog.mxml contains a simple Label control with an id of “TheMessage”.

 

Anywhere in the application you have the following lines of code:

 

this.currentState = “systemMessageVisible”;

this.TheSystemMessageDialog.TheMessage.text = “This is the message text.”;

 

 

The problem I am running into is, that when the code executes the *first* time, I get a null pointer exception. I guess the reason is, that once you switch to a new state the *first* time, the component – in this case TheSystemMessageDialog – must first be created/instantiated. So once the main execution path reaches the statement which tries to change the text of the label included inside the component, it cannot do so, because the component does not yet exist. Subsequent state changes work perfect. I guess once created the instance of the component is kept, even if you restore an older state.

 

However: How would I design my requirements into the application then? From the docs I have understood that states have been introduced as a convenient way to easily show/hide GUI components. But how can I use this great feature if the properties and methods to configure components in a state are not accessible prior to switching to it?

 

Your advice is much appreciated!

 

Ralf Rottmann

 



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to