Accessing get vars with ActionScript 3

I’ve just started to learn a bit of ActionScript for a new project I’m working on. The first thing I needed to do was integrate a message from the source html (and eventually a php file.) Turns out there’s pretty much no clear documentation out there on the web, so I decided to write this.

First thing’s first, create a text object in your flash file and set the instance name to something you can easily remember, in this example I set it to message. Once you’ve done that, on the keyframe for the layer in which that peice of text is, right click it and click on actions, then add the following:

this.message.text = LoaderInfo(this.root.loaderInfo).parameters.mymessage;

Easy enough, now you can publish your html. Once published, remove all the javascript stuff and the <noscript> tags surrounding the embed code [note, there’s probably a better way of doing all this and I’ll update this post once I figure it out.]

<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="test.swf?mymessage=workingok" quality="high" bgcolor="#ffffff"
  width="600" height="450" name="test" align="middle" allowScriptAccess="sameDomain"
  allowFullScreen="false" type="application/x-shockwave-flash" 
  pluginspage="" />

That’s basically where you set the variables you want to pass to flash. You have to urlencode each parameter. If you don’t know what that means, google it.

Leave a Reply