Passing vars from JS to AS3 is really easy, but it’s not as easy as it was with AS2.
Here I use the excellent SWFObjects (I use it in all my web projects now) to pass variables to the Flash Player:
so.addVariable("var1", "value1");
so.addVariable("var2", "value2");
Now to get the values with AS3 when you already know the variable name:
var myValue1:String = this.loaderInfo.parameters.var1;
var myValue2:String = this.loaderInfo.parameters.var2;
If you want to trace all the variables (names and values) passed to the Flash Player:
for ( var theName:String in this.loaderInfo.parameters ) {
var theValue:String = this.loaderInfo.parameters [theName];
trace(“from JS :”+ theName+” “+theValue);
}
[adsenseyu1]
Does it really differ comparing to AS2? I just pass all the variables I need using well known FlashVars and access them in any Class via Application.application.parameters associative array (e. g. Application.application.parameters.userId).
Pingback: myFeedz - Articles on "cs3"
Pingback: feed-squirrel.com - Flash
Pingback: AS3 Tuturial - Variables from JavaScript To Flash CS3 « Flash Enabled - Get Ready With Flash…
Pingback: Beedigital, talking about Flash & Resources
Pingback: passare dei parametri alla Document Class (FCS3) - Wave9 Forums
Man, you saved my day, thanks a lot!
Pingback: Metah - A Web Technologist Adventure » Blog Archive » Holy Grail: SEO Model for Flash and Flex Content
Pingback: flashcrobat » Blog Archive » Flash and JavaScript
Pingback: Flash tutorials | Flash vs Javascript | Lemlinh.com
Thanks for the trace function. I’ll snippet it for later use. How can you send a var from AS3 to Javascript? Or modify a Javascript var from within Flash. I want to grab the width and height from the onmetadata of a FLV, resize the player according to those values, and then send out those values to be used with swfobject. I have all the vars placed and AS3 complete, I just need to know how to send them out so swfobject can read them. Thanks!!
Pingback: Easy GameJolt Flash Api integration for Games (As3) - Monster Brain inc