Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh an application in Flex?

I have designed a quiz application in Flex 4. At the end I want to reload my application (that is refresh the page in the browser). At the end I will show score in an alert. After that I want to reload the current application. How can I do this?

like image 806
Santhosh Nayak Avatar asked Aug 02 '11 12:08

Santhosh Nayak


2 Answers

To cause the refresh to not happen until after your alert is clicked:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*" 
               >
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.FlexGlobals;
            import mx.events.CloseEvent;
            protected function refreshClicked(event:Event):void
            {
                Alert.show("Congratulations you won", 
                    "Hooray!", 
                    Alert.NO|Alert.YES, null, refreshFinish);
            }
            protected function refreshFinish(event:CloseEvent=null):void{
                if(event == null){
                    event = new CloseEvent("refreshFinish");
                    event.detail = Alert.YES;
                }
                if(event.detail == Alert.YES){
                    navigateToURL(new URLRequest(FlexGlobals.topLevelApplication.url), "_self");
                }
            }
        ]]>
    </fx:Script>
    <s:Button label="Alert and Refresh" click="refreshClicked(event)" />
</s:Application>

You can remove the option of "NO" by removing it from the or as the 3rd parameter of Alert.show.

like image 179
SuperSaiyen Avatar answered Sep 22 '22 08:09

SuperSaiyen


just navigate back to your website :)

navigateToURL(new URLRequest("linktoyourwebsite"));

to get the current page's url, you can use the following code:

import flash.external.ExternalInterface;

var pageURL:String = ExternalInterface.call('window.location.href.toString');

so your code then becomes:

var pageURL:String = ExternalInterface.call('window.location.href.toString');
navigateToURL(new URLRequest(pageURL));
like image 43
Michiel Standaert Avatar answered Sep 21 '22 08:09

Michiel Standaert