1 Reply Latest reply on Aug 29, 2008 2:17 AM by Newsgroup_User

    Page Refresh ( F5)

    josh_aries Level 1
      Hi All,
      I am working on an application that has the login page as the entry page. Only after the user logs in the linkbar and the other pages are accessible to him. Everything works fine till here. But when the user refreshes the page ( F5) the user goes back to the login page instead of refreshing the same page.

      I am trying to use the Shared Object to store the index but thats not working. I am not sure if I am doing something wrong

      Here is my sample code.


      Attach Code

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application creationComplete="isReloaded();"
      verticalGap="0" width="100%" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical"
      height="100%" xmlns:Comp="*" horizontalAlign="center" >
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;

      public var mySO:SharedObject = SharedObject.getLocal("userDetails");

      private function isReloaded():void
      {
      if( mySO.data.viewIndex != null )
      vs.selectedIndex = mySO.data.viewIndex;
      vs.visible = false;
      vs.includeInLayout= false;
      Menu.visible = false;
      Menu.includeInLayout= false;


      }

      private function saveIndex():void
      {
      mySO.data.viewIndex = vs.selectedIndex;
      mySO.flush();
      }
      ]]>
      </mx:Script>
      <mx:HBox width="80%" verticalGap="0" horizontalAlign="center">
      <mx:VBox verticalGap="0" horizontalAlign="center">
      <mx:Image id="imgLogo" source="../assets/images/NiyumHeader.jpg"/>
      <mx:LinkBar visible="false" includeInLayout="false" verticalGap="0" color="#FFFFFF" width="100%" selectionColor="#FFFFFF" backgroundColor="#000000" fontSize="11" horizontalGap="30" id="Menu" dataProvider="{vs}"></mx:LinkBar>
      <Comp:login label="Login" width="100%" height="100%" id="loginMenu" />
      <mx:ViewStack visible="false" includeInLayout="false" change="saveIndex();" verticalGap="0" id="vs" width="100%" height="100%">
      <Comp:menu1 label="menu 1" id="menuOne" width="100%" height="100%" />
      <Comp:menu2 label="menu2" id="menuTwo" width="100%" height="100%" />
      </mx:ViewStack>
      </mx:VBox>
      </mx:HBox>
      </mx:Application>



      login.mxml





      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox horizontalAlign="center"
      xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      public function LoginButton_Click():void{
      Alert.show("Button Click");
      this.parentApplication.vs.selectedIndex = 0;
      this.parentApplication.Menu.visible = true;
      this.parentApplication.Menu.includeInLayout = true;
      this.parentApplication.vs.visible = true;
      this.parentApplication.vs.includeInLayout = true;
      this.visible = false;
      this.includeInLayout = false;
      }
      ]]>
      </mx:Script>
      <mx:Form>
      <mx:FormHeading label="Login"/>
      <mx:FormItem label="User Name:">
      <mx:TextInput id="txtUserName"/>
      </mx:FormItem>
      <mx:FormItem label="Password:">
      <mx:TextInput id="txtPassword"/>
      </mx:FormItem>
      </mx:Form>
      <mx:Button id="btnSubmit" click="LoginButton_Click();" label="Login" fontSize="12"/>
      </mx:VBox>

      menu1.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:Label text="World" />
      </mx:Canvas>


      menu2.mxml


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:Label text="Hello" />
      </mx:Canvas>