actionscript-3apache-flexflex4flashvars

as3 get FlashVars in flex 4


I want to get FlashVars in my html using action script,

the < OBJECT > tag in html like:

            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="test.swf" width="550" height="400">
                <param name="movie" value="test.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="FlashVars" value="acc=3001&pwd=test">
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflash">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->

and my action script is use as a model in flex that used by mxml, so I don't have movieclip or I cannot use this.loaderInfo.parameters; or root since there isn't a displayObject.

Is there other method to grab the FlashVars value in as3,

or can I get FlashVars in mxml then let as3 get the variable such as:

var paramObj:Object = Application(FlexGlobals.topLevelApplication).parameters;
var test:String;
test = paramObj['acc'];

and in as3:

var getText:String = test;

Thanks in advance.


Solution

  • You will have access to the FlexGlobals anywhere in the application since the topLevelApplication is static type, it could be even in the AS file. So, instead of doing that in the MXML file, you could do that in the AS file itself