Search code examples
flashactionscript-3deep-linkingswfaddress

AS3 - swfaddress deep linking when someone pastes a url


I have swfaddress (2.4) working fine on my site - the back button works, I can copy and paste urls and be taken to the correct page, etc.

BUT, if I copy a url, say "http://mysite.com/#/bio", and paste it into a new browser window, the site always just loads to the home page after the preloader. What am I missing? Do I somehow need to check the url when the page loads?


Solution

  • Without seeing any of your code...There's two events you're going to be interested in watching for. When your app starts up you should listen for

    SWFAddress.addEventListener(SWFAddressEvent.INIT, __init);
    

    Which would then register the CHANGE listener:

    private function __init(event:SWFAddressEvent):void
    {
        SWFAddress.addEventListener(SWFAddressEvent.CHANGE, __handle);
    }
    

    Your handler function should handle changes in the URL. This will handle the beginning url when it first initializes and when you use SWFAddress.setValue() to change the page:

    private function __handle(event:SWFAddressEvent):void
    {
        var address:String = SWFAddress.getValue();
        // -- perform actions based on addresss
    }