Search code examples
flashactionscript-3swfobject

is there any of passing flashvars in static publishing method of SWF_Object?


Well i just want to know that using static publishing method SWF-Object , can we pass flashvars to flash swf file??

The static publish method is

<head>
    <title>SWFObject 2 static publishing example page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="embedswf/swfobject.js"></script>
    <script type="text/javascript">
    swfobject.registerObject("myId", "9.0.0", "embedswf/expressInstall.swf");
    </script>
</head>

<body>
    <div>   
        <object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="750" flashvars="var1=irfan" params="var1=irfan">
            <param name="movie" value="fish.swf" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="fish.swf" width="600" height="750" flashvars="var1=irfan" params="var1=irfan">
            <!--<![endif]-->
            <div>
                <h1>Alternative content</h1>
                <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
            </div>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </div>
</body>

but the flashvars and params are not passed to flash file??


Solution

  • I think what you're asking is if you've got a statically embedded SWF using SWFObject.... thats about the only way that really makes sense. In that case the answer is yes. Even if your embed tag was dynamically generated using PHP or something, you can still pass flash vars. Easiest way to do this is to download and install the swfObject AIR app for generating your embed tag.

    http://code.google.com/p/swfobject/downloads/list

    You'll see an area for flashvars. It's simply key/value pairs so create a key, "keyname" and populate it with your data. Then in AS3 inside your main class (or anywhere really) you can access this data like so:

    root.loaderInfo.parameters.keyname;
    

    So lets say you have a key "userName" with the value "myUser". You can get this like so:

    var uName:String = root.loaderInfo.parameters.userName;
    trace(uName);
    

    Obviously you're gonna want to do some basic checking to ensure these objects exist and what not, but this is pretty much how you access flash vars, and also happens to be the same way you access GET variables on the SWF url.