topical media & game development

talk show tell print

mashup-rmx-07-Chapter7-Exercise4-components-CustomCanvas.mx

mashup-rmx-07-Chapter7-Exercise4-components-CustomCanvas.mx (swf ) [ flash ] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Canvas 
          xmlns:mx="http://www.adobe.com/2006/mxml" 
          implements="mx.managers.IHistoryManagerClient" 
          creationComplete="initComp()" 
          currentStateChange="viewChanged()">
          
          <mx:Script>
                  <![CDATA[
                          import mx.managers.HistoryManager;
                          
                          private function initComp():void{
                                  HistoryManager.register(this);
                          }
                          
                          private function viewChanged():void{
                                  HistoryManager.save();
                          }
                          
                          public function saveState():Object{
                                  return {currentState: currentState};
                          }
                          
                          public function loadState(state:Object):void{
                                  var newState:* = state ? state.currentState : '';
                                  if(newState != currentState) currentState = newState;
                          }
                  ]]>
          </mx:Script>
          
          <mx:states>
                  <mx:State name="Welcome">
                          <mx:RemoveChild target="{button}"/>
                          <mx:AddChild>
                                  <mx:Text text="Welcome to my site!!"/>
                          </mx:AddChild>
                  </mx:State>
          </mx:states>
          
          <mx:Button id="button" label="Enter Here" click="this.currentState='Welcome'"/>
          
  </mx:Canvas>
  


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.