0 Replies Latest reply on Feb 17, 2008 7:15 AM by Starlover_jacob

    custom pagehistory

    Starlover_jacob Level 1
      Here a simple example of a custom page history.
      files: viewstack_example.mxml, vstack_test.mxml, Pagehistory.as


      viewstack_example.mxml


      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical"
      verticalAlign="middle"
      backgroundColor="white"
      xmlns:local="*">

      <mx:Script>
      <![CDATA[
      import mx.core.Container;
      import mx.controls.*;

      private function toV0():void
      {
      Pagehistory.savePage(myviewstack.selectedChild);
      myviewstack.selectedIndex=0;
      Alert.show("gesaved");
      }
      private function toV4():void
      {
      Pagehistory.savePage(myviewstack.selectedChild);
      myviewstack.selectedChild=myviewstack.v4;
      Alert.show("gesaved");
      }
      private function previous():void
      {
      var currentpage:Container=myviewstack.selectedChild;
      var pagetoload:Container=Pagehistory.getPreviousPage(currentpage);
      myviewstack.selectedChild=pagetoload;
      }
      ]]>
      </mx:Script>

      <mx:ApplicationControlBar dock="true">
      <mx:Button label="v1" click="toV0();" />
      <mx:Button label="v4" click="toV4();" />
      <mx:Button label="previous" click="previous();" />

      <mx:Spacer width="100%" />

      </mx:ApplicationControlBar>

      <local:vstack_test id="myviewstack"/>

      </mx:WindowedApplication>





      vstack_test.mxml


      <?xml version="1.0" encoding="utf-8"?>
      <mx:ViewStack xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%">
      <mx:VBox backgroundColor="haloBlue"
      width="100%"
      height="100%"
      id="v1">
      <mx:Label text="VBox 1" />
      </mx:VBox>
      <mx:VBox backgroundColor="haloGreen"
      width="100%"
      height="100%"
      id="v2">
      <mx:Label text="VBox 2" />
      </mx:VBox>
      <mx:VBox backgroundColor="haloOrange"
      width="100%"
      height="100%"
      id="v3">
      <mx:Label text="VBox 3" />
      </mx:VBox>
      <mx:VBox backgroundColor="haloSilver"
      width="100%"
      height="100%"
      id="v4">
      <mx:Label text="VBox 4" />
      </mx:VBox>
      </mx:ViewStack>



      Pagehistory.as


      package
      {
      import mx.core.Container;

      public class Pagehistory
      {
      static private var historyarray:Array=null;

      static public function savePage(selectedpage:Container):void
      {
      if(historyarray==null)
      {
      historyarray= new Array();
      }

      historyarray.push(selectedpage);
      }
      static public function getPreviousPage(selectedpage:Container):Container
      {
      if(historyarray!=null && historyarray.length>0)
      {
      return historyarray.pop();
      }
      else
      {
      return selectedpage;
      }
      }
      }
      }




      Sorry for the way i put it here.. I could not find the attach code button.
      Greetz, jacob