tags:

views:

490

answers:

3

Hi,

I was working with my application which shows login first time and goes to the second screen after successful validation. But there is a problem occurs when browser get refresh by F5 or browser button the application gets reloaded and shows the very first screen i.e. the Login screen.

How to avoid this, I mean irrespective of browser reloading the current screen/component should remain intact (it should not start with the beginning).

As an example I have a link from where I took this example & uses in my code: http://www.vipercreations.com/media/tutorials/login_system_with_flex_and_php/
credentials: user: test and pass: test

Here, once u logged in and press F5 you will back to the Ist screen rather than staying at the same screen.

Thanks,Shuo

A: 

Ofcourse it will reload, it is not the flash who is reloaded.. its the whole web page. or HTML file.

I have this code to disable F5 or refresh

<script>
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{

case 116 : // 'F5'
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>
Treby
But Treby,It's really not a good idea to disable F5 or refresh,that's not what I want,thanks anyway.
Shuo
+2  A: 

If your login creates something like a session you can pass that same session object to the application via FlashVars.

When your application is starting, test if a session is already existing. If existing, validate it against the server. If successful: you are logged in, so skip the login screen. Otherwise: show login screen.

Besides: This is not a refresh issue but boils down to session management. Instead of hitting the refresh button I could also open the same website again and would have to login which seems akward.

Joa Ebert
I'm afraid that Flex doesn't support Session.
Shuo
It does not have to support them. On login, you call a web service, which generates, stores and returns a session to your client application (written in MXML).Next time you reload the website with the Flex application your server is responsible for inserting the session into the FlashVars object. Another possibility is also to have the Flex application ask for a possible existing session on the backend.
Joa Ebert
Thanks Joa!But to be honest,I'm not a professional on Flex,could you please write some code or give me an example?Thanks in advance!
Shuo
A: 

You could store the sessionID in a cookie via ExternalInterface or in a shared object. This way you can even add a expiration date that of course should be in sync with the serverside expiration of the session.

Additionally you can use the HistoryManager or the BrowserManager to encode states of the app in the URL. If you design the states carefully, hitting F5 (or accessing the page via bookmarks) will direct the browser to the last state instead of the beginning. Just remember to verify the session.

Jörg Reichardt
Thanks,Jorg.But I'm not a professional on Flex,could you please give me an example?
Shuo
Well, using the HistoryManager is a rather advanced topic, I'm afraid.See the Livedocs on Deep Linking: http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_8.htmlAs for setting the the cookie, that's qite simple. with ExternalInterface.call(...); you can call any JavaScript function, e.g. ExternalInterface.call("function writeSession(){ document.cookie = 'sessionid=" + sessionID + ", expires=" + sessionEnd +"'}"); or something like that (sorry, I'm not able to verify the code atm)
Jörg Reichardt