开发者

Modify components that is not included in the current state?

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


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! :)


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}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜