Skip to main content
October 9, 2007
Question

Reading Querystring into FLASH variable

  • October 9, 2007
  • 14 replies
  • 793 views
I can't believe I can't make this work. I've even done this in the past, but everything I try, fails.

i want FLASH to read the querstring value from the address bar, apply that value to a variable, and be able to use it. I've read the articles all over the net about grabbing the QS value in the page that loads the SWF and sticking it into the embed and movie tags as well as the ones about using PARAM=FLASHVARS etc.

can't make it work.

I can grab the QS value in the .asp page that loads the SWF, but I can't for the life of me pass that value into FLASH. Can someone please give me two things:

1. whats the most effective/efficient way to pass the variable
2. the syntax for assigning the value to a variable in FLASH

Thanks tons all!
This topic has been closed for replies.

14 replies

kglad
Community Expert
Community Expert
October 9, 2007
it looks like you need to know the number of variable/value pairs in the query string if you use the swfObject. that restriction would not be present if you use javascript to parse the url.
Inspiring
October 9, 2007
Another way to do it is to use swfobject for embedding instead of the adobe ac_fl_runcontent javascript.
Swfobject has an existing utility method for this very purpose - you can just add info to a flashvar when it does the embedding so its immediately available on the timeline. There are some examples on the swfobject website. Take a look at the bottom of the section titled
Passing variables into your movies using the "Flashvars" parameter:
Here:
http://blog.deconcept.com/swfobject/#examples
kglad
Community Expert
Community Expert
October 9, 2007
use javascript to extract the query string from the url and use the flash externalinterface class to pass that to flash.
October 9, 2007
found something new to try, but still no luck...but closer maybe:

This is the code generated by Dreamweaver when I dump the FLASH into the page PLUS what I added:

<script type="text/javascript">
AC_FL_RunContent( 'codebase',' http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','859','height','1250','src','randomItemGallery_v2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','bgcolor','#000000','movie','randomItemGallery_v2','FlashVars','galpick','allowScriptAccess','sameDomain'); //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,28,0" width="859" height="1250">
<param name="movie" value="randomItemGallery_v2.swf" />
<param name="quality" value="high" />
<param name="BGCOLOR" value="#000000" />
<param name="FlashVars" value="galpick=<%=strGallery%>" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="randomItemGallery_v2.swf" width="859" height="1250" quality="high" pluginspage=" http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#000000" flashvars="galpick=<%=strGallery%>" allowScriptAccess="sameDomain"></embed>
</object>
</noscript>

I added:
'FlashVars','galpick' to the AC_FL_RunContent block
<param name="FlashVars" value="galpick=<%=strGallery%>" /> to the object block
flashvars="galpick=<%=strGallery%>" to the embed block

<%=strGallery%> is called above all of this to grab the querystring item I need to pass in. In this case it is g=2. This is working...when I view the source of the ASP page, the embed and object blocks of code have the right value for galpick


Then in the FLASH file on frame one:

var galvar:String
var keyStr:String
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
galvar = String(paramObj[keyStr]);
}

from what the code tutor said, this should grab the param passed by flashvar and write it to the variable galvar

Then I put a dynamic text box on stage and gave it an instance name of galpicker and added this code to the FLASH file:

galpickertxt.text = galvar;

When I load the page on the server, the text box reads undefined.