1 Reply Latest reply on Jul 11, 2008 10:13 AM by EDendramis

    Page Refresh (F5)

    josh_aries Level 1
      I have an application where the first screen is a login screen, when
      a user logs in he is redirected to a diferent view based on the users
      login permissions etc. The problem is whenever we hit the F5 browser
      button the wrapper file is refreshed and the embeddd swf (flex app)
      is reloaded reinitializing all the application variables etc. This
      takes the screen view back to the default login screen although the
      user is logged and all values are lost.
      How can I handle this?
      Any configuration change etc. Do we need to disable the F5 key press using javascript
      etc. ?

      Please advise.


      <?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>


      and the login page iis

      <?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>