Apache flex 如何在Flex中刷新应用程序?
我在Flex4中设计了一个测验应用程序。最后,我想重新加载我的应用程序(即在浏览器中刷新页面)。最后,我将在警报中显示分数。之后,我想重新加载当前的应用程序。我该怎么做 只需导航回您的网站:) 要获取当前页面的url,可以使用以下代码:Apache flex 如何在Flex中刷新应用程序?,apache-flex,actionscript-3,browser,flex4,Apache Flex,Actionscript 3,Browser,Flex4,我在Flex4中设计了一个测验应用程序。最后,我想重新加载我的应用程序(即在浏览器中刷新页面)。最后,我将在警报中显示分数。之后,我想重新加载当前的应用程序。我该怎么做 只需导航回您的网站:) 要获取当前页面的url,可以使用以下代码: import flash.external.ExternalInterface; var pageURL:String = ExternalInterface.call('window.location.href.toString'); 因此,您的代码将变成
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));
要使刷新在单击警报后才发生,请执行以下操作:
<?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>
您可以将“否”选项从或中删除,作为Alert.show的第三个参数。另一个答案。
我们必须调用AS3中的函数
ExternalInterface.call("reload");
在javascript中的html文件中,我们必须定义函数重载
function reload()
{
window.location.reload(true);
}
我使用的代码是:var urlRequest:urlRequest=newurlrequest(Application.Application.url);导航URL(URL请求,“_self”);但它不起作用(我编辑了我的答案。我添加了获取当前页面url的方法:)谢谢你的回答。但应用程序正在新窗口中打开;
function reload()
{
window.location.reload(true);
}