[英]Flex4 Application state in a custom component
I'm porting my Flex3 app to Flex4 (FlashBuilder4). 我正在将我的Flex3应用程序移植到Flex4(FlashBuilder4)。 I get the whole new state concept, except one thing.
除了一件事,我得到了整个新的状态概念。 In a custom component (separate mxml file) I'm using the main level Application's state.
在自定义组件(单独的mxml文件)中,我使用的是主级别应用程序的状态。 In Flex3 it was:
在Flex3中,它是:
<mx:State name="only_view_mode">
<mx:RemoveChild target="{myComponent.button1}" />
</mx:State>
In Flex4 it should be something like that : 在Flex4中,应该是这样的 :
<mx:State name="only_view_mode" />
and 和
<mx:LinkButton id="button1" excludeFrom="???" />
My question is: how can I access to an Application state from a component? 我的问题是:如何从组件访问应用程序状态? I checked the official reference ( http://www.adobe.com/go/learn_flex4_alldocumentation_en ) and Google of course but without any success.
我检查了官方参考资料( http://www.adobe.com/go/learn_flex4_alldocumentation_cn )和Google,但都没有成功。
Thanks in advance 提前致谢
Try using 尝试使用
FlexGlobals.topLevelApplication.currentState
FlexGlobals.topLevelApplication.currentState
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/FlexGlobals.html?filter_flex=4 http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/mx/core/FlexGlobals.html?filter_flex=4
That didn't really work since it requires a String. 那实际上没有用,因为它需要一个字符串。 I tried it in every possible way I could figure out.
我尽我所能尝试了所有方法。 So far I came with this very ugly solution: I add an event listener for checkint state changes of my main level component:
到目前为止,我提供了一个非常丑陋的解决方案:我为主要级别组件的checkint状态更改添加了一个事件侦听器:
<?xml version="1.0" encoding="utf-8"?>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="{onCreationComplete();}">
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.events.StateChangeEvent;
private function onCreationComplete():void {
FlexGlobals.topLevelApplication.addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE, onStateChanged);
}
private function onStateChanged(event:StateChangeEvent):void {
currentState = event.newState;
}
]]>
</fx:Script>
<s:states>
<s:State name="default" />
<s:State name="login" />
</s:states>
<s:TextArea includeIn="login"/>
</s:Panel>
Please let me know if there is a better solution. 请让我知道是否有更好的解决方案。 Btw, I have a hunch that the basedOn attribute of State component is the way to go.
顺便说一句,我有一种直觉,即State组件的basedOn属性是必经之路。 But don't know what kind of format it expects:
但不知道它期望哪种格式:
<s:State name="login" basedOn="???" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.