Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Setting flashvars in AS3 when testing movie

Guest
Apr 08, 2009 Apr 08, 2009

Does anyone know how to set flashvars when running a movie in CS4 using Control->Test Movie?  Under ActionScript 2 I could just set _root.flashVar, what's the equivalent in AS3?

TOPICS
ActionScript
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 08, 2009 Apr 08, 2009

When I'm testing flashvars locally I usually just set them to something manually in my code.  Then remove it once I put it on the server.

//the name of my flashvar is myVar

var myVar;

myVar = "magic";

.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 09, 2009 Apr 09, 2009

Hi Dan,

Thanks, but I'm not quite understanding what this solution is.  Is the AS2 that you're thinking in terms of when you're posting this solution?

In AS3, the flashvar parameters don't appear as top level properties, they are found under "root.loaderInfo.parameters".  So I can look up a parameter like this:

trace("myVar=" + root.loaderInfo.parameters.myVar);

I'd like to be able to do something like setting this parameter in my test code like this:

root.loaderInfo.parameters.myVar="test value";

...but this doesn't seem to work.  No error message when I try this (either running "Test Movie" in CS4 or running in Flash Player in FireFox).  Looking at the doc page for flash.display.LoaderInfo, it says that the "parameters" property is readonly.

I wish there were some kind of dialog in CS4 to allow me to set up flash vars for testing under Control->Test Movie, but if there is such a thing, I haven't found it yet!

- Bruce

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 09, 2009 Apr 09, 2009

Here's what I do:

myVar = "test value"

//myVar = root.loaderInfo.parameters.myVar

Then I use myVar as the variable in my code.  When I'm ready to go live with it I remove the top line and uncomment the 2nd line.  Make sense?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2009 Jun 26, 2009
LATEST

Here's what I do to prevent having to comment out code when going live, in this case I'm building a nav of some sort where the labels and links of the buttons in the nav are provided through flash vars:

var testFlashVarObj:Object = {
                labels_1 : "1,2,3,4,5",
                links_1 : "http://www.1.com,http://www.2.com,http://www.3.com,http://www.4.com,http://www.5.com,",
                labels_2 : "1,2,3,4,5",
                links_2 : "http://www.1.com,http://www.2.com,http://www.3.com,http://www.4.com,http://www.5.com,"
            };
           
flashVarsObj = LoaderInfo(this.root.loaderInfo).parameters.labels_1 ? LoaderInfo(this.root.loaderInfo).parameters : testFlashVarObj;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines