Recent site activity

    Home‎ > ‎Web Development‎ > ‎Tools‎ > ‎Flash‎ > ‎

    Passing Parameters

    Invocation / instantiation

    Passing parameters to Flash CS3 / Actionscript 3 is a little tricky.

    There are two ways that I've found to work:

    Pass by Query String

    Remember, the URL params are passed with the SWF file, not the browser URL. If you want to retrieve values from the URL, you can do something like this.

    Pass by Flashvars

    as JSON parameter in swfobject.embedSWF():
    flashvars={ p1: "value1", p2: "value2" }

    as param tag in HTML:
    <param name="flashvars" value="p1=value1&p2=value2" />

    Note: the "so.addVariable" SWFObject approach has been deprecated.
    so.addVariable("p1","value1"); so.addVariable("p2","value2");

    Access in Flash

    In Actionscript 3, the variables are not automatically available, so they need to be retrieved. Regardless of how the parameters are passed, all are retrieved together.


    var keyStr:String;
    var valueStr:String;
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    for (keyStr in paramObj)
    valueStr = String(paramObj[keyStr]);
    // do something with valueStr


    var param1:String = this.root.loaderInfo.parameters.p1;
    var param2:String = this.root.loaderInfo.parameters.p2;