Archive for October, 2008

Application.application.url in Flash AS3

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.

Add comment October 16th, 2008



About: I work as a Platform Evangelist for Adobe Systems Incorporated.

My Amazon.com Wish List

Calendar

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

Posts by Month

Posts by Category


Flex.org - The Directory for Flex