Thursday, December 2, 2010

Passing and Accessing a parameter for SWF



/***********************************************************************
Description:Here is one of the implementation of passing and accessing a parameter to SWF file.
Following code is compiled in Adobe Flash Professional CS5.
***********************************************************************/




Passing the parameter with in your html while embedding the SWF file:


<embed src=MyPlayer.swf" menu="false" quality="high" width="226" height="200" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="my_parameter=my_parameter_value" ></embed>


Accesing the parameter with in your SWF implementation code:

// implement loadParams() as event function for creationComplete event
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="loadParams()" preloaderChromeColor="#E51F1F" xmlns:s="library://ns.adobe.com/flex/spark" width="290">

// access your parameter inside the loadParams() function
string strMyParameterValue = this.parameters["my_parameter"];