Getting external parameters in ActionScript 3

ActionScript 3.0

Actually this is not a big or complex post. I am a part time ActionScript 3.0 developer and recently in my company i2we, inc. I developed a customized jobs search widget for them. Where one of the criteria was when we include flash object in html, we can provide external parameter. Based on the parameter the flash widget customize its result.

So in this post, I will show how you can pass parameter from html and get them in your flash object. Please keep in mind that my code is based on ActionScript 3.0

Look at the html code

<object classid="clsid:xxxxxxxxxxxxxx" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="250" height="370" id="widget" align="middle">
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="allowFullScreen" value="false" />
            <param name="movie" value="http://mysite.com/widget.swf?company=facebook" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="http://mysite.com/widget.swf?company=facebook" quality="high" bgcolor="#ffffff" width="250" height="500" name="widget" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
            </object>

Look I pass parameter company = facebook

http://mysite.com/widget.swf?company=facebook

Now I capture this parameter in my flash widget using actionscript by the following way

var globalParam = LoaderInfo(this.root.loaderInfo).parameters;
for (var element:String in globalParam) {
     if (element == 'company'){
           company =   globalParam[element];
     }
}

This actionscript 3.0 codes first loads global parameters and put them in globalParam variable. Now I just check whether there is a parameter named company or not. As I provided the company parameter in html so within flash object, I will get company = facebook

Very easy, right? Cheers!

About mahmud ahsan

Founder And Lead Programmer at iThinkdiff.net

, , ,

3 Responses to Getting external parameters in ActionScript 3

  1. Andres July 2, 2010 at 11:58 pm #

    It does not work

    1120: Access of undefined property company.

  2. Wyatt Richlin August 2, 2010 at 10:30 am #

    Hm ,.. Yes the best way is to just play like my friend Brenton Berber he just play games and enjoy his life.

  3. Alex Mercer October 20, 2010 at 4:30 am #

    thx… work’s fine

    to Andres, try to initializate a variable named ‘company’ before loop…