Amit
Amit

Reputation: 34793

Flex - How to pass parameters to a swf

I am using FlashVars to pass params in the swf but it is not working.

Here is the html code:

<noscript>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="tpc">
            <param name="movie" value="tpc.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="allowFullScreen" value="true" />
            <param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye">

            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="tpc.swf" width="100%" height="100%">
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="allowFullScreen" value="true" />
                **<param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye">**

            <!--<![endif]-->
            <!--[if gte IE 6]>-->
                <p> 
                    Either scripts and active content are not permitted to run or Adobe Flash Player version
                    10.0.0 or greater is not installed.
                </p>
            <!--<![endif]-->
                <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>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </noscript>     

Here is the .mxml file code:

            var keyStr:String;
            var valueStr:String;

            var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

            var length:int = 0;

            for (keyStr in paramObj) {
                length++;
            }

            if (length == 0) {
                ta.appendText("Length is zero so below is the dummy data:\n");
                paramObj = {test:"Test", test2:"Test2"};
            }

            for (keyStr in paramObj) {   
                valueStr = String(paramObj[keyStr]);
                ta.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
            }

Upvotes: 0

Views: 5908

Answers (2)

J_A_X
J_A_X

Reputation: 12847

First, don't use that HTML. Use swfobject to embed your Flash swf into your html. It's easier to do and supported by Adobe.

Second, you're not accessing the vars properly and probably trying to access the vars too soon. You need to wait for the application's creationComplete event before trying to access it. There's a real good tutorial on everything I just said on Adobe Help.

Upvotes: 3

Marty
Marty

Reputation: 39466

Within the <object> try adding an <embed> like this:

<embed src="file.swf?myVariable=Hello%20World&mySecondVariable=Goodbye" width="" height="" />

Upvotes: 0

Related Questions