AIR从StageWebView获取LocationChangeEvent.LOCATION_CHANGING的哈希值

时间:2012-12-04 17:02:23

标签: flash flex air stagewebview

我正在构建一个基于HTML的AIR应用程序,为了调用ActionScript方法,我在HTML应用程序的URL上附加了具有特定模式的哈希标记(#AIRBRIDGE_methodName_arguments)。使用window.location ='#AIRBRIDGE_methodName_arguments';在HTML应用程序的JavaScript中调用AIR LocationChangeEvent.LOCATION_CHANGING事件,但是当我尝试访问StageWebView.location值时,不会返回哈希值。

有没有人有这方面的经验?这是ActionScript代码:

public function LoadHtmlPageByName(pageName:String, stage:Stage):void
    {
        stage.scaleMode = StageScaleMode.EXACT_FIT;

        webView = new StageWebView(); 
        webView.stage = stage;
        webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, onLocationChange);
        webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

        var htmlPath:String = new File(new File("app:/assets/html/" +  pageName + "#something").nativePath).url;
        webView.loadURL(htmlPath);
    }

    public function onLocationChange(event:LocationChangeEvent):void
    {
        trace("you are now at: ", webView.location);
    }

2 个答案:

答案 0 :(得分:3)

而不是#(哈希锚定),对window.location使用未知协议。

示例:window.location =" unknown:/ and_add_here_your_method_info"。

Adob​​e Air可以通过LocationChangeEvent.LOCATION_CHANGE或LOCATION_CHANGING捕获它。

iOS注意事项:     还要收听EventError.Error。在我使用Adobe Air 3.4的情况下,window.location的值被传递给EventError.text。所以也要检查一下。

答案 1 :(得分:0)

如果您没有重新加载页面,我猜“位置”不会改变。 您可以尝试更改和阅读页面标题,但我不确定如果未重新加载页面,它将会更改。