Santhosh Nayak
Santhosh Nayak

Reputation: 2288

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?

Upvotes: 5

Views: 7367

Answers (3)

Santhosh Nayak
Santhosh Nayak

Reputation: 2288

another answer. we have to call function in AS3

ExternalInterface.call("reload"); 

in html file within javascript we have to define function reload

 function reload()
    {
    window.location.reload(true);
    }

Upvotes: 0

Michiel Standaert
Michiel Standaert

Reputation: 4176

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));

Upvotes: 3

SuperSaiyen
SuperSaiyen

Reputation: 1410

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.

Upvotes: 3

Related Questions