AboutFlex.net

flex,air,flash …



This example shows you how to implement the interface that enables you to activate the back button of the browser;In this example the IHistoryManagerClient interface is implemented into a component;
in the same way you can implement it in the application.

Click here to view the example in action

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	xmlns:creativesource="it.creativesource.*" width="420"
	height="320" paddingLeft="10" paddingRight="10"
	paddingTop="10" pageTitle="10">

	<creativesource:HistoryManger x="10" y="10" />

</mx:Application>

The Component :

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
	initialize="initApp()"
	implements="mx.managers.IHistoryManagerClient" >
	<mx:states>
		<mx:State name="STATE1">
			<mx:SetProperty target="{text1}" name="text" value="State 1"/>
		</mx:State>
		<mx:State name="STATE2">
			<mx:SetProperty target="{text1}" name="text" value="State 2"/>
		</mx:State>
		<mx:State name="STATE3">
			<mx:SetProperty target="{text1}" name="text" value="State 3"/>
		</mx:State>
	</mx:states>
	<mx:Script>
		<![CDATA[
			import mx.events.StateChangeEvent;
			import mx.managers.HistoryManager;

			public function initApp() :void{
				HistoryManager.register(this);
				addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,handleStateChange);
			}

			private function handleStateChange(e:StateChangeEvent):void {
			    HistoryManager.save()
			}
			public function loadState(historyState:Object) :void{
				removeEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
				handleStateChange);

				if (historyState == null){
					currentState = "";
				}else{
					currentState = historyState.currentState;
				}

				addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
				handleStateChange);

			}
			public function saveState() :Object{
				var historyState:Object = new Object();
				historyState.currentState = currentState;
				return historyState;
			}
		]]>
	</mx:Script>
	<mx:Text text="StartState" y="93" fontSize="18" id="text1" horizontalCenter="0"/>
	<mx:HBox x="96" y="268">

	<mx:Button click="currentState='STATE1'" label="State1"/>
	<mx:Button click="currentState='STATE2'" label="State2"/>
	<mx:Button click="currentState='STATE3'" label="State3"/>
	</mx:HBox>
</mx:Canvas>

Add A Comment