flashapache-flexairstagewebview

AIR Get hash value on LocationChangeEvent.LOCATION_CHANGING from StageWebView


I am building an HTML-based AIR app and in order to invoke ActionScript methods, I append hash tags on the HTML app's URL with specific patterns (#AIRBRIDGE_methodName_arguments). Using window.location = '#AIRBRIDGE_methodName_arguments'; in the JavaScript of the HTML app invokes the AIR LocationChangeEvent.LOCATION_CHANGING event, but when I try to access the StageWebView.location value the hash is not returned.

Has anyone had experience with this? Here is the ActionScript code:

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

Solution

  • Instead of # (hash anchoring), use an unknown protocol for window.location.

    Example: window.location="unknown:/and_add_here_your_method_info".

    Adobe Air can trap that through LocationChangeEvent.LOCATION_CHANGE or LOCATION_CHANGING.

    Notes for iOS: Also listen to EventError.Error. In my case using Adobe Air 3.4, the value of window.location is being passed to EventError.text. So also check on that.