Daniel J F
Daniel J F

Reputation: 1064

Get swf URL from AS3

I need to get URL of my SWF from ActionScript 3 in order to parse it (cannot use loaderInfo.parameters).

I've tried to use root.loaderInfo.url but it returns null. FlexGlobals.topLevelApplication.url throws an error, because topLevelApplication doesn't exist. Am I missing something?

Upvotes: 0

Views: 429

Answers (1)

Daniel J F
Daniel J F

Reputation: 1064

OK, got it. As Yasuyuki Uno suggested in the comment, url property should be called after INIT event.

So I had

public function MyClass()
{
    root.loaderInfo.url;  // null
}

And it should be

import flash.events.Event;

public function MyClass()
{
    root.loaderInfo.addEventListener(Event.INIT, _onInit);
}

private function _onInit(ev:Event) : void
{
    root.loaderInfo.url;  // we have the URL now
}

Upvotes: 2

Related Questions