ACE

Calendar

July 2008
S M T W T F S
  1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31  

Tag Cloud

360Flex actionscript air air 2 android apple as3 books conference contest cookbook deeplinking Dreamweaver F3 v. F4 FileReference flash flash builder Flash Player flashplayer flashplayer10 Flex flex3 flex4 flexbuilder flickr fotobooth google gumbo ImageDropR InsideRIA iphone java load() localconnection max max 2009 merapi microsoft mobile nexus one pixel bender save() SilverLight training updatemanager

Categories

Archives

Recent Posts

Recent Comments


« Good news for RIA and SWF | Main | Merapi is now available for download »

Flex Applications that Warn on Close

By Rich Tretola | July 2, 2008
3,436 views

Occasionally, there are times when you need to give the user the heads up that closing the application could cause issues as there are processes currently running.

This example shows an easy way to do this via the FABridge. Click the link below to run the sample.

Warn On Close

So, how does it work?

Here are the steps to take to add this functionality.

Add an instance of the FABridge to your main Application file
1
<bridge:FABridge bridgeName="flex"/>
Create 2 variables within your main Application file to hold a warning on/pff flag and a message.
1
2
public var warnUser:Boolean;
public var warningMessage:String;
Create a JavaScript file that will call a function before the browser window closes. The contents of the file should look something like this. Notice that the confirmExit function simply creates a variable to hold a reference to the Flex application. It then checks to see if it should warn the user by reading the warnUser ActionScript property (the FABridge JavaScript object uses implicit getters and setters when reading and writting ActionScript variables), finally it will alert the user with the custom message stored in the warningMessage property.
1
2
3
4
5
6
7
8
9
10
window.onbeforeunload = confirmExit;

function confirmExit()
{
  var flexApp = FABridge.flex.root();
    if(flexApp.getWarnUser())
    {
        return flexApp.getWarningMessage();
    }
}
The last thing you need to do is update your index.template.html file to include your custom JavaScript and the FABridge.js files.
1
2
3
4
<!--  BEGIN Warn on Close -->
<script src="bridge/FABridge.js" language="javascript"></script>
<script src="bridge/WarningBridge.js" language="javascript"></script>
<!--  END Warn on Close -->

That’s it. To avoid security sandbox errors, just make sure you run the sample through a web server and not a file path. Here is the full source code.

Topics: Flex 3 (Moxie) | 3 Comments »

3 Responses to “Flex Applications that Warn on Close”

PeZ Says:
July 2nd, 2008 at 9:20 am

Thanks but It doesn’t work neither on Safari 3.1 (Mac) nor on Opera 9.5(Mac)

Reply to this comment

Daniel Neri Says:
July 2nd, 2008 at 10:11 am

Fantasic, thanks!

Just the thing I needed ;)

Reply to this comment

everythingflex Says:
July 2nd, 2008 at 11:30 am

Hm, you are right, I tried it in Safari 3.1 and it doesn’t work. I am not sure why.

Reply to this comment

Comments



You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser