movie.swf?vars=how_do_you_do_dat
Filed under Lab Work, Programming | Tags:external variables,Flash,variables
You can pass variables to a swf using flashvars, or better, with “?” followed by the variable name and it’s value. I’m super bad when it comes to using shortcuts, but i do it anyway. So, in AS3, it’s a bit different from the code perpective inside your movie. The process in the HTML is the same. Using swfobject, or just the embed tag , you can pass that variable with the trusty “?” but, how you access from inside the movie is the part that has changed a bit. The bottom line is you need to use the loaderInfo.parameters expression to get that variable value. So, if i am trying to pass a variable called “pick” and a variable called “imageName”, i will embed the movie like so:
var pickvalue=5; var imageNameValue="0.jpg" var swfO=new swfobject("movie.swf?pick="+pickvalue+"&imageName="+imageNameValue,"divID","500","400","9"); </code> then, in my actionscript, i have two private variables, “pick” and “imageName”- i can access the outside variables, passed to the movie like so: <code> this.pick=root.loaderInfo.parameters.pick this.imageName=root.loaderInfo.parameters.imageName;