
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);
}
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).
[...] Passing variable from JavaScript To AS3 (Flash CS3) details » http://www.metah.ch Posted 6 hours ago by Metah Flash Blog feed details » [...]
[...] Passing variable from JavaScript To AS3 (Flash CS3) 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 proj [...]
[...] You can find the tutorial here. [...]
[...] View tutorial here. [...]
[...] ciao, in realta’ questo e’ un falso problema perche’ questi parametri eventualmente GIA’ esistono in loaderInfo.parameters: http://www.metah.ch/blog/2007/07/04/…as3-flash-cs3/ a occhio e croce direi che a livello di document class gli unici parametri che puoi passare in fase di creazione sono quelli via FlashVars. Jaco a scanso di equivoci, prima di interpretare una risposta leggi con cura qui: http://www.linuxtrent.it/documentazi…deIntelligenti wannabeFlasher.addEventListener(event.WORLD, learn); [...]
Man, you saved my day, thanks a lot!
[...] To access the XML URL from ActionScript: [...]
[...] A brief and basic recollection about passing vars from JS to AS3. found on: metah.ch [...]
[...] Read more [...]
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!!