Accessing FlashVars in ActionScript 3

jglazer63
jglazer63 used Ask the Experts™
on
I want to create a FlashVar:

<param name="FlashVars" value="xmlFile=something.xml" />

But I cannot seem to get the actionscript 3 code to pull in this variable (xmlFile).  Can anyone give an example?

In addition, how can I set the flash developer up so that I can test with FlashVars?  I cannot seem to set them in publish settings anywhere.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If it's Flex use following:
------------------
Application.application.parameters.xmlFile


And if it's Flash AS3:
----------------------
root.loaderInfo.parameters.xmlFile


Can you clarify this line in your question, I didn't get it:
"In addition, how can I set the flash developer up so that I can test with FlashVars?  I cannot seem to set them in publish settings anywhere."

Commented:
Example for package/class:

import flash.display.Stage;

...

public static function getValue(key:String):String {
  return Stage.loaderInfo.parameters[key];
}
What exactly is what you are trying to do? Are you going to get a different xml file depending on an action (for example, clicking a button) or you just want to load an xml when a certain page is loaded?
Ah, and answering your last question, as far as I know and maybe I'm wrong, you can't test flashvars directly on the Flash IDE. You have to text it by opening the web page the swf is embedded in.

Commented:
If you are using the html wrapper generated by the flex builder IDE then you need to specify the flashvars in three places
PLACE 1:

AC_FL_RunContent(
                  "src", "${swf}",
                  "width", "${width}",
                  "height", "${height}",
                  "align", "middle",
                  "id", "${application}",
                  "quality", "high",
                  "bgcolor", "${bgcolor}",
                  "name", "${application}",
                  "allowScriptAccess","sameDomain",
                  "type", "application/x-shockwave-flash",
                  "pluginspage", "http://www.adobe.com/go/getflashplayer",
                  
                  "flashvars","file=xmlFile.xml"
                  
                  
                  
      );

PLACE 2:

                  
                  
                  
                  
                  

PLACE 3:



                  
                  

Author

Commented:
Simple and just what i needed

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial