Not yet rated

Problem

You need to load flashvars from a default generated FlexBuilder / AS Project..

Solution

Use LoaderInfo() to retrieve the variables

Detailed explanation

HTML CODE:

Flex / FlashBuilder will generate a sample HTML code which you can use directly, altough I prefer to use SWFObject, this is quite a good starting point if you don't want to mess around with HTML

Inside the Noscript tag use
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="${application}" width="${width}" height="${height}"
            codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
            <param name="movie" value="${swf}.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="${bgcolor}" />
            <param name="allowScriptAccess" value="sameDomain" />
             <param name="flashVars" value="aTest=helloWorld&bTest=how%20are%20you" />
            <embed src="${swf}.swf" quality="high" bgcolor="${bgcolor}"
                width="${width}" height="${height}" name="${application}" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                type="application/x-shockwave-flash"
                pluginspage="http://www.adobe.com/go/getflashplayer"
                flashVars="aTest=helloworld&bTest=How%20are%20you">
            </embed>
    </object>

Inside the Script tag
else if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
            "src", "${swf}",
            "width", "${width}",
            "height", "${height}",
            "align", "middle",
            "id", "${application}",
            "quality", "high",
            "bgcolor", "${bgcolor}",
            "name", "${application}",
            "flashVars", "aTest=helloWorld&bTest=how%20are%20you",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );

Moving on to AS3 Code:

public class HelloFlashVars extends Sprite
    {
       
        private var aTest                        :String;
        private var bTest                        :String;
       
        public function HelloFlashVars()
        {
            aTest = this.loaderInfo.parameters.aTest;
            bTest = this.loaderInfo.parameters.bTest;
           
            trace(aTest);
            trace(bTest);
        }
    }


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes