« [Transient] metadata Tag
» Constant XML not so constant?

ActionScript, Flex 2, RIA

FABridge: Warn on flex application exit

Virgil Cristea | 25.10.07 | Comment?

One of the most common problems in the RIA applications that require login/logout and also some saves is how to prevent the user from closing the window/tab when there is unsaved information?

The answer is simple: FABridge.

This functionality allows you to catch the unload event from javascript and execute your flex code.

Here is how:

First you need to create a public variable in your application

public var isAppDirty:Boolean = false;

That variable is set to true whenever changes occur that must be saved.

Second you need to modify your html wrapper. It is located in the html-templates folder.

window.onbeforeunload = confirmExit;
 
function confirmExit()
{
  var flexApp = FABridge.flash.root();
  var appDirty = flexApp.isAppDirty();
 
  // Note that the isAppDirty var is called like a function.
  // This is done deliberately. Thats the way FABridge works
  if (appDirty == true)
  {
    return "Data has changed. If you wish to save the data, click CANCEL, if not click OK.";
  }
}

Third you need to include the FABridge libraries in the html -<script language=”JavaScript” type=”text/javascript” src=”bridge/FABridge.js”></script>. You can download the FABridge libraries from here.

There also are some ways of injecting the FABridge libraries from actionscript, and it will come in a later post.

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , , , , ,

This post was written by Virgil Cristea

Views: 1580

related

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« [Transient] metadata Tag
» Constant XML not so constant?