Application.application.url in Flash AS3

October 16th, 2008

The solution to accessing the loader information url property is quite easy in Flash ActionScript 3. But when you Google for the solution its not obvious. Hence I am creating a post about it.

In Flex you can access the url of the SWF by accessing Application.application.url. What this value represents is the root.loaderInfo.url property. So in Flash and AS3 you would do this:

ACTIONSCRIPT:
  1. var tf:TextField = new TextField();
  2. tf.autoSize = TextFieldAutoSize.LEFT;
  3. tf.border = true;
  4. addChild(tf);
  5.  
  6. tf.appendText("params:" + "\n");
  7. try {
  8.     var keyStr:String;
  9.     var valueStr:String;
  10.     tf.appendText(LoaderInfo(this.root.loaderInfo).url + "\n");
  11.     var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
  12.     for (keyStr in paramObj) {
  13.         valueStr = String(paramObj[keyStr]);
  14.         tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
  15.     }
  16. } catch (error:Error) {
  17.     tf.appendText(error.toString());
  18. }

The important part is accessing the root's loaderInfo object. The above code also shows how to access the FlashVar parameters in ActionScript 3.

Example code referenced from here.

Entry Filed under: Adobe Flex

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Disclaimer: I work as a Flash/Flex Developer for Adobe Systems Incorporated. The opinions expressed here represent my own and not those of my employer.

My Amazon.com Wish List

Calendar

October 2008
S M T W T F S
« Aug   Dec »
 1234
567891011
12131415161718
19202122232425
262728293031  

Most Recent Posts


Flex.org - The Directory for Flex