Sunday, November 14, 2010

Passing variables to Flash through HTML using AS3

In today's short tutorial we will learn how to pass variables to a flash through HTML.

You can do that through the FlashVars param value. For example:

<object data="myflash.swf" 
style="height: 400px; width: 550px;"
type="application/x-shockwave-flash">
<param name="movie" value="myflash.swf">
<param name="wmode" value="opaque">

<param name="FlashVars" value="myVariable=100" />

</object>

And then you can access this using the following line of AS3 code:

trace(root.loaderInfo.parameters.myVariable);

If you want to pass multiple variables, separate them using the & symbol:

<object data="myflash.swf" 
style="height: 400px; width: 550px;"
type="application/x-shockwave-flash">
<param name="movie" value="myflash.swf">
<param name="wmode" value="opaque">

<param name="FlashVars" value="myVariable=100&myOtherVariable=200" />

</object>


Easy as that!

Thanks for reading!

No comments:

Post a Comment