tags:

views:

96

answers:

2

In Flex 4, is it possible to modify components that is not include in the current state? For example, I have labelA included in stateA, how do I change the label text in stateB? If I directly change the label text in stateB, I'll get an null reference error message.

One workaround is to include labelA in all states, and set it to be invisible in states other than stateA. However, if the number of this kind of component goes too large, the work becomes tedious, and also I don't think it's reasonable to include unnecessary UI components in unrelated states. Is there better solution for this situation? Thanks!

Regards

A: 

Do not modify the text on a label yourself. Instead you can create a variable (a String) which will hold the text, bind the labels text value to that variable, and than only change the value of the variable. Something similiar to this:

<fx:Script>
    <![CDATA[           
        [Bindable]
        private var yourLabelText:String = 'this is the text'; 
    ]]>
</fx:Script>
<s:Label text="{yourLabelText}" />
Robert Bak
A: 

Thanks for the response. So if this case is common, I'll expect there will be lots of bindable variable declarations in my codes, like

[Bindable]
private var a:String;
[Bindable]
private var b:String;
[Bindable]
private var c:String;

and so on. Am I right? Thanks, again! :)