如何在 Flex 中刷新应用程序?

发布于 2024-11-27 14:57:40 字数 92 浏览 2 评论 0原文

我在 Flex 4 中设计了一个测验应用程序。最后我想重新加载我的应用程序(即刷新浏览器中的页面)。最后我会在警报中显示分数。之后我想重新加载当前的应用程序。我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷情妓 2024-12-04 14:57:40

要使刷新在单击警报后才发生:

<?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>

您可以通过将“NO”选项从或作为 Alert.show 的第三个参数删除来删除该选项。

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.

音栖息无 2024-12-04 14:57:40

只需导航回您的网站:)

navigateToURL(new URLRequest("linktoyourwebsite"));

要获取当前页面的 url,您可以使用以下代码:

import flash.external.ExternalInterface;

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

因此您的代码将变为:

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

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));
苹果你个爱泡泡 2024-12-04 14:57:40

另一个答案。
我们必须

ExternalInterface.call("reload"); 

在 javascript 中的 html 文件中调用 AS3 中的函数,我们必须定义函数 reload

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

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文