How to use Flashvars with AS3

remember flashvars from AS2? its still there in AS3 but you access it differently.

in the HTML ActiveContent Javascript code add the flashvars parameter:


AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '490',
'height', '490',
'src', 'ColorGen',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'ColorGen',
'bgcolor', '#ffffff',
'name', 'ColorGen',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'ColorGen',
'salign', '',
'flashvars', 'boxColor=0x0000FF'
); //end AC code

(see the second last line)

And you should throw the same flashvars parameter in the object tag in the noscript for those who have JS disabled like this:

… now when you want to access it, instead of doing a _level0.boxColor like in AS2, you simply do a:

loaderInfo.parameters.boxColor

and bada-bing.

And of course you could add more flashvars name-value pairs separated by &’s… kinda like URL parameters

why a whole blog post on this? cuz i didn’t see it in AS3 LR on livedocs, and i could imagine wasting a lot of time on this if i didn’t work at adobe and didn’t have access to our massive testing library.

thought i’d share.

And by the way, here’s some more information from livedocs:

http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001005.html#166514

http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001585.html#171273

And here’s an URL if you want to use flashvars with Flex:
http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001004.html

7 Responses to How to use Flashvars with AS3

  1. Hendrik says:

    Thanks for the tip Amir. I’ve spent around 6 hours just getting a variable into Flash.Got it working in 10 seconds after reading about the activecontent js code.

  2. Scott Hall says:

    How can you pass the Flashvars if you can’t use javascript? Can you?from amir: yes you can, you would put it in the object/embed tag, this is the old way to do it. Look up the documentation on this on livedocs

  3. Even says:

    Men you’r the best, tanks

  4. ed says:

    Hi Amir, I am trying to make a box, (FLVPlayback component), not worried about skins but want to change the content path by editing the html. I have CS3, the AS2 example didn’t work until the AC script was ammended. Do you have an example of how I can achieve that above. The content is coming off FMS2 streaming server, many thanks in advance Ed——————–amir: ed, just use flashvars… just know that you might have to escape JS characters like quotes.

  5. ed says:

    Hi Amir, many thanks for that above, it helped my get my first flashvars working. On another subject, do you have an efficient way of streaming mp3 from FMS2. I have managed to do it in AS2 however have to specify the file in ns.play and filepath in nc.connect. Ideally I want to pass just one complete filepath to a swf via flashvars? best regards ed______________amir: yeah just put it in flashvars, you might have to URL Encode it first. So in the JS code, make it “flashvars”, “path/to/the/sound.mp3″ …. or you could just use the old school and tags.

  6. James says:

    Thanks for reminding me about the AC code! Great article.

  7. Darash says:

    Hey thanks. Found exactly what I was looking for a long time. Saved me a lot of time.Bless you!