<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; parameters</title>
	<atom:link href="http://blog.flexexamples.com/tag/application-parameters/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grabbing FlashVars from the embedding HTML template</title>
		<link>http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/</link>
		<comments>http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 05:34:20 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[HTML template]]></category>
		<category><![CDATA[parameters]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/</guid>
		<description><![CDATA[<p>What if you built a nice, custom FLV player in Flex and wanted to embed the player in an HTML page and have it star playing a specific video? How could you easily do that without tweaking the MXML each time with the path to the FLV or calling a server-side script to somehow determine [...]]]></description>
			<content:encoded><![CDATA[<p>What if you built a nice, custom FLV player in Flex and wanted to embed the player in an HTML page and have it star playing a specific video? How could you easily do that without tweaking the MXML each time with the path to the FLV or calling a server-side script to somehow determine the video you wanted to play? Well, one of the easiest solutions is to tweak the generated embed code and pass in any custom variables you wanted using &#8220;FlashVars&#8221;.</p>
<p>No idea what I&#8217;m talking about? Well, check out the following Flex 2.0.1 docs for more of a background: <a href="http://livedocs.adobe.com/flex/201/html/passingarguments_086_05.html">&#8220;Using flashVars&#8221;</a> and <a href="http://livedocs.adobe.com/flex/201/html/passingarguments_086_04.html">&#8220;Using the Application.application.parameters object&#8221;</a>.</p>
<p>Full code after the jump.</p>
<p><span id="more-64"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Application_application_parameters_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code" language="actionscript">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function init():void {
                // The FlashVars
                var obj:Object = Application.application.parameters;
                var item:String;

                arrColl = new ArrayCollection();

                /* Populate the ArrayCollection object with the FlashVars. */
                for (item in obj) {
                    arrColl.addItem({key:item, value:obj[item]});
                }

                dataGrid.dataProvider = arrColl;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="arrColl" /&gt;

    &lt;mx:DataGrid id="dataGrid" /&gt;

&lt;/mx:Application&gt;
</pre>
<p>Next, open the generated *.html template in the /bin/ directory and add the &#8220;FlashVars&#8221; key and a string of name/value pairs, as shown in the following snippet:</p>
<pre class="code" language="javascript">
AC_FL_RunContent(
    "src", "main",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "main",
    "quality", "high",
    "bgcolor", "#869ca7",
    "name", "main",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
    <b style="color:red;">&quot;FlashVars&quot;, &quot;name=peter&amp;site=flexexamples.com&quot;</b>
);
</pre>
<p>And then you need to change the &lt;object /&gt; and &lt;embed /&gt; tags in the &lt;noscript /&gt; block, as seen in the following snippet:</p>
<pre class="code">
&lt;noscript&gt;
      &lt;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
            id=&quot;${application}&quot; width=&quot;${width}&quot; height=&quot;${height}&quot;
            codebase=&quot;http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab&quot;&gt;
            &lt;param name=&quot;movie&quot; value=&quot;${swf}.swf&quot; /&gt;
            &lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
            &lt;param name=&quot;bgcolor&quot; value=&quot;${bgcolor}&quot; /&gt;
            &lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;
            <strong style="color:red;">&lt;param name=&quot;flashVars&quot; value=&quot;url=woo&quot; /&gt;</strong>
            &lt;embed src=&quot;${swf}.swf&quot; quality=&quot;high&quot; bgcolor=&quot;${bgcolor}&quot;
                width=&quot;${width}&quot; height=&quot;${height}&quot; name=&quot;${application}&quot; align=&quot;middle&quot;
                play=&quot;true&quot;
                loop=&quot;false&quot;
                quality=&quot;high&quot;
                allowScriptAccess=&quot;sameDomain&quot;
                <strong style="color:red;">flashVars=&quot;url=woo&quot;</strong>
                type=&quot;application/x-shockwave-flash&quot;
                pluginspage=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;
            &lt;/embed&gt;
    &lt;/object&gt;
&lt;/noscript&gt;
</pre>
<p>Save the HTML document and open it in a browser and you should see your name/value pairs parsed and displayed nicely in your DataGrid control. Of course, the Flex code used a loop and ArrayCollection object to nicely display the data in the DataGrid control. You could just as easily referenced the variables like <code>Application.application.parameters.name</code> and <code>Application.application.parameters.site</code>.</p>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Application_application_parameters_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Application_application_parameters_test/bin/main.html" width="100%" height="220"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Grabbing FlashVars from the embedding HTML template on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/',contentID: 'post-64',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'parameters',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

