Flash Querystrings in AC_RunActiveContent.js

Leave a comment
geek

For the benefit of anyone as baffled as I was half an hour ago: if you try to pass a variable to a SWF via the Querystring (or FlashVars) and it just doesn’t work, try this. For some inexplicable reason it seems to be not covered fully in the Flash documentation.

When you publish in Flash CS3, the HTML that is created looks like this (in this case the FLA is called ‘passtest’):

<script language=”javascript”>

if (AC_FL_RunContent == 0) {

alert(“This page requires AC_RunActiveContent.js.”);

} else {

AC_FL_RunContent(

‘codebase’, ‘http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0’,

‘width’, ‘550’,

‘height’, ‘400’,

‘src’, ‘passtest’,

‘quality’, ‘high’,

‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,

‘align’, ‘middle’,

‘play’, ‘true’,

‘loop’, ‘true’,

‘scale’, ‘showall’,

‘wmode’, ‘window’,

‘devicefont’, ‘false’,

‘id’, ‘passtest’,

‘bgcolor’, ‘#ffffff’,

‘name’, ‘passtest’,

‘menu’, ‘true’,

‘allowFullScreen’, ‘false’,

‘allowScriptAccess’,’sameDomain’,

‘movie’, ‘passtest’,

‘salign’, ”

); //end AC code

}

</script>

<noscript>

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0″ width=”550″ height=”400″ id=”passtest” align=”middle”>

<param name=”allowScriptAccess” value=”sameDomain” />

<param name=”allowFullScreen” value=”false” />

<param name=”movie” value=”passtest.swf” /><param name=”quality” value=”high” /><param name=”bgcolor” value=”#ffffff” /> <embed src=”passtest.swf” quality=”high” bgcolor=”#ffffff” width=”550″ height=”400″ name=”passtest” align=”middle” allowScriptAccess=”sameDomain” allowFullScreen=”false” type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/getflashplayer” />

</object>

</noscript>

Assuming you want to pass the variable kittens=wonderful, because they are, this needs to be changed to (note changes in bold text):

<script language=”javascript”>

if (AC_FL_RunContent == 0) {

alert(“This page requires AC_RunActiveContent.js.”);

} else {

AC_FL_RunContent(

‘codebase’, ‘http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0’,

‘width’, ‘550’,

‘height’, ‘400’,

‘src’, ‘passtest’,

‘quality’, ‘high’,

‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,

‘align’, ‘middle’,

‘play’, ‘true’,

‘loop’, ‘true’,

‘scale’, ‘showall’,

‘wmode’, ‘window’,

‘devicefont’, ‘false’,

‘id’, ‘passtest’,

‘bgcolor’, ‘#ffffff’,

‘name’, ‘passtest’,

‘menu’, ‘true’,

‘allowFullScreen’, ‘false’,

‘allowScriptAccess’,’sameDomain’,

‘movie’, ‘passtest?kittens=wonderful‘,

‘salign’, ”

); //end AC code

}

</script>

<noscript>

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0″ width=”550″ height=”400″ id=”passtest” align=”middle”>

<param name=”allowScriptAccess” value=”sameDomain” />

<param name=”allowFullScreen” value=”false” />

<param name=”movie” value=”passtest.swf?kittens=wonderful” /><param name=”quality” value=”high” /><param name=”bgcolor” value=”#ffffff” /> <embed src=”passtest.swf?kittens=wonderful” quality=”high” bgcolor=”#ffffff” width=”550″ height=”400″ name=”passtest” align=”middle” allowScriptAccess=”sameDomain” allowFullScreen=”false” type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/getflashplayer” />

</object>

</noscript>

The key bit not mentioned in the documentation is the first change in the first script block. The querystring needs to be appended to the movie (not SRC) parameter, and without the .swf in the filename.

Once this is done the variable kittens will now be available as _root.kittens. You can append several variables as you would in HTML (?thisvar=that&theother=somethingelse), and all must be URL encoded.

And that’s it. Normal cats photos / train company problem posts will resume immediately.

Leave a Reply