Flex 4中是否有可用于检测状态更改的事件?
siv3szwd1#
我知道这个问题是旧的,但通过谷歌搜索状态变化事件,我仍然得到这里,所以对于想知道的人:有一个由组件调度的StateChangeEvent.CURRENT_STATE_CHANGE事件,因此您的应用程序也可以侦听该事件。在侦听器函数中,您可以访问StateChangeEvent.oldState和StateChangeEvent.newState属性。
StateChangeEvent.CURRENT_STATE_CHANGE
StateChangeEvent.oldState
StateChangeEvent.newState
bgtovc5b2#
如果您讨论的是视图状态,那么答案是肯定的,您可以侦听enterState事件,如下所示(很抱歉示例过于简单,它是我正在处理的项目的一部分,我删除了代码中的任何相关部分):
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="800" minHeight="600" currentState="loading"> <fx:Script> <![CDATA[ import mx.controls.Alert; private function onEnterLoadingState():void{ Alert.show("Enter the loading state.", "Application"); } private function onEnterLoginState():void{ Alert.show("Enter the login state.", "Application"); } private function onEnterAddState():void{ Alert.show("Enter the addUser state.", "Application"); } private function changeState(state:String):void{ currentState = state; } ]]> </fx:Script> <s:states> <s:State name="loading" enterState="onEnterLoadingState()"/> <s:State name="login" enterState="onEnterLoginState()"/> <s:State name="addUser" enterState="onEnterAddState()"/> </s:states> <s:Panel id="loadView" includeIn="loading" title="Loading"> <s:Button label="Go to login" click="changeState('login')"/> </s:Panel> <s:Panel id="loginView" includeIn="login" title="Login"> <s:Button label="Go to addUser" click="changeState('addUser')"/> </s:Panel> <s:Panel id="addView" includeIn="addUser" title="AddUser"> <s:Button label="Return to loading" click="changeState('loading')"/> </s:Panel> </s:Application>
如果您需要exitState事件的话,这里还有一个exitState事件。希望这对您有所帮助。
zkure5ic3#
您可以在任何UIComponent类上侦听多个状态事件:
MXML:
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" enterState="windowedapplication1_enterStateHandler(event)" exitState="windowedapplication1_exitStateHandler(event)" currentStateChange="windowedapplication1_currentStateChangeHandler(event)" currentStateChanging="windowedapplication1_currentStateChangingHandler(event)" stateChangeInterrupted="windowedapplication1_stateChangeInterruptedHandler(event)" stateChangeComplete="windowedapplication1_stateChangeCompleteHandler(event)"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function windowedapplication1_stateChangeCompleteHandler(event:FlexEvent):void { } protected function windowedapplication1_stateChangeInterruptedHandler(event:FlexEvent):void { } protected function windowedapplication1_currentStateChangeHandler(event:StateChangeEvent):void { var oldState:String = event.oldState; var newState:String = event.newState; } protected function windowedapplication1_currentStateChangingHandler(event:StateChangeEvent):void { var oldState:String = event.oldState; var newState:String = event.newState; } protected function windowedapplication1_enterStateHandler(event:FlexEvent):void { } protected function windowedapplication1_exitStateHandler(event:FlexEvent):void { } ]]> </fx:Script> </s:WindowedApplication>
3条答案
按热度按时间siv3szwd1#
我知道这个问题是旧的,但通过谷歌搜索状态变化事件,我仍然得到这里,所以对于想知道的人:
有一个由组件调度的
StateChangeEvent.CURRENT_STATE_CHANGE
事件,因此您的应用程序也可以侦听该事件。在侦听器函数中,您可以访问
StateChangeEvent.oldState
和StateChangeEvent.newState
属性。bgtovc5b2#
如果您讨论的是视图状态,那么答案是肯定的,您可以侦听enterState事件,如下所示(很抱歉示例过于简单,它是我正在处理的项目的一部分,我删除了代码中的任何相关部分):
如果您需要exitState事件的话,这里还有一个exitState事件。希望这对您有所帮助。
zkure5ic3#
您可以在任何UIComponent类上侦听多个状态事件:
MXML: