<?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; FlashVars</title>
	<atom:link href="http://blog.flexexamples.com/category/flashvars/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 in Flex 4 (SWFObject Edition)</title>
		<link>http://blog.flexexamples.com/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/</link>
		<comments>http://blog.flexexamples.com/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 08:05:49 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[HTML template]]></category>
		<category><![CDATA[SWFObject]]></category>
		<category><![CDATA[parameters]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/</guid>
		<description><![CDATA[<p>In a previous entry, <a href="http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/">&#8220;Grabbing FlashVars from the embedding HTML template&#8221;</a>, we saw how you could access FlashVars in your Flex application by passing a name/value pair string to the AC_FL_RunContent() method and &#60;object&#62;/&#60;embed&#62; tags from your HTML template.</p> <p>The following example shows how you can pass FlashVars from your HTML template to your [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous entry, <a href="http://blog.flexexamples.com/2007/08/07/grabbing-flashvars-from-the-embedding-html-template/">&#8220;Grabbing FlashVars from the embedding HTML template&#8221;</a>, we saw how you could access FlashVars in your Flex application by passing a name/value pair string to the <code>AC_FL_RunContent()</code> method and &lt;object&gt;/&lt;embed&gt; tags from your HTML template.</p>
<p>The following example shows how you can pass FlashVars from your HTML template to your Flex applications using the Flex 4 SDK (which uses SWFObject now, by the way).</p>
<p>Full code after the jump.</p>
<p><span id="more-991"></span></p>
<p class="alert">To use the following code, you must have Flash Player 10 and a Flex 4 SDK installed in your Flex Builder 3. For more information on downloading and installing the Flex 4 SDK into Flex Builder 3, see <a href="http://blog.flexexamples.com/2008/08/02/using-the-beta-gumbo-sdk-in-flex-builder-3/">&#8220;Using the beta Flex 4 SDK in Flex Builder 3&#8243;</a>.</p>
<p class="download"><a href="">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/ --&gt;
&lt;FxApplication name="SWFObject_flashvars_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        backgroundColor="white"
        applicationComplete="init();"&gt;
    &lt;layout&gt;
        &lt;BasicLayout /&gt;
    &lt;/layout&gt;

    &lt;Script&gt;
        import mx.utils.ObjectUtil;

        private function init():void {
            textArea.text = ObjectUtil.toString(this.parameters);
        }
    &lt;/Script&gt;

    &lt;FxTextArea id="textArea"
            selectable="true"
            left="20"
            right="20"
            top="20"
            bottom="20" /&gt;

&lt;/FxApplication&gt;
</pre>
<p>And my [slightly modified] HTML template code is as follows:</p>
<p class="download"><a href="">View HTML template</a></p>
<pre class="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;!-- saved from url=(0014)about:internet --&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;/title&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
        &lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
            html, body    { height:100%; }
            body { margin:0; padding:0; overflow:hidden; text-align:center; }
            #flashContent { display:none; }
        &lt;/style&gt;

        &lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
            var swfVersionStr = &quot;10.0.12&quot;;
            var xiSwfUrlStr = &quot;playerProductInstall.swf&quot;;
            var flashvars = {};
            <strong style="color:red;">flashvars.userAgent = navigator.userAgent;
            flashvars.userLanguage = navigator.userLanguage;
            flashvars.onLine = navigator.onLine;
            flashvars.name = &quot;peter&quot;;
            flashvars.team = &quot;Flex SDK&quot;;
            flashvars.twitter = &quot;<a href="http://twitter.com/pdehaan">http://twitter.com/pdehaan</a>&quot;;</strong>
            var params = {};
            params.quality = &quot;high&quot;;
            params.bgcolor = &quot;#ffffff&quot;;
            params.allowscriptaccess = &quot;sameDomain&quot;;
            var attributes = {};
            attributes.id = &quot;SWFObject_params_test&quot;;
            attributes.name = &quot;SWFObject_params_test&quot;;
            attributes.align = &quot;middle&quot;;
            swfobject.embedSWF(
                &quot;SWFObject_params_test.swf&quot;, &quot;flashContent&quot;,
                &quot;100%&quot;, &quot;100%&quot;,
                swfVersionStr, xiSwfUrlStr,
                flashvars, params, attributes);
            swfobject.createCSS(&quot;#flashContent&quot;, &quot;display:block;text-align:left;&quot;);
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;flashContent&quot;&gt;
            &lt;p&gt;
                To view this page ensure that Adobe Flash Player version
                10.0.12 or greater is installed.
            &lt;/p&gt;
            &lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;Get Adobe Flash Player&lt;/a&gt;
        &lt;/div&gt;
   &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And the generated output from the code is:</p>
<pre class="code">
(Object)#0
  name = "peter"
  onLine = "true"
  team = "Flex SDK"
  twitter = "http://twitter.com/pdehaan"
  userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)"
  userLanguage = "en-us"
</pre>
<p class="alert">This entry is based on a beta version of the Flex Gumbo SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex Gumbo SDK.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Grabbing FlashVars from the embedding HTML template in Flex 4 (SWFObject Edition) on FlexExamples.com',url: 'http://blog.flexexamples.com/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/',contentID: 'post-991',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'Application,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/2009/03/04/grabbing-flashvars-from-the-embedding-html-template-in-flex-gumbo-swfobject-edition/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using HTTPService tag to send/receive variables to a server-side script</title>
		<link>http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/</link>
		<comments>http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 21:28:20 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[lastResult]]></category>
		<category><![CDATA[send()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/</guid>
		<description><![CDATA[<p>The following example demonstrates a very simple usage of sending parameters from Flex to a server-side script (written in ColdFusion) and then displaying the server response in our Flex application. The server-side script is a simple echo/&#8221;Hello world&#8221; type script, but it accepts URL or FORM variables, so you can send using the GET or [...]]]></description>
			<content:encoded><![CDATA[<p>The following example demonstrates a very simple usage of sending parameters from Flex to a server-side script (written in ColdFusion) and then displaying the server response in our Flex application. The server-side script is a simple echo/&#8221;Hello world&#8221; type script, but it accepts URL or FORM variables, so you can send using the GET or POST HTTP-method.</p>
<p>It&#8217;s a pretty basic/crude example, but maybe it helps somebody out there.</p>
<p>Full code after the jump.</p>
<p><span id="more-94"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_post_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        creationComplete="httpService.send(myObj);"&gt;

    &lt;!-- Parameters to send to remote script. --&gt;
    &lt;mx:Object id="myObj" name="peterd" /&gt;

    &lt;mx:HTTPService id="httpService"
            url="http://www.flash-mx.com/mm/greeting.cfm"
            method="POST"
            resultFormat="flashvars" /&gt;

    &lt;mx:Label text="{httpService.lastResult.welcomeMessage}" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_post_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/HTTPService_post_test/bin/main.html" width="100%" height="100"></iframe></p>
<p class="new">By popular request, here is the ColdFusion source code as well.</p>
<p class="download">http://www.flash-mx.com/mm/greeting.cfm</p>
<pre class="code">
&lt;cfsilent&gt;
&lt;cfsetting enablecfoutputonly=&quot;Yes&quot;&gt;
&lt;cfif IsDefined(&quot;URL.name&quot;)&gt;&lt;cfset Form.Name = URL.name /&gt;&lt;/cfif&gt;
&lt;cfif NOT IsDefined(&quot;Form.name&quot;) OR Len(Trim(Form.Name)) EQ 0&gt;
    &lt;cfset Form.Name = &quot;[Mysterious Stranger]&quot; /&gt;
&lt;/cfif&gt;
&lt;/cfsilent&gt;&lt;cfcontent reset=&quot;true&quot; /&gt;&lt;cfoutput&gt;welcomeMessage=#UrlEncodedFormat(&quot;Welcome, &quot;&#038;Form.name)#&lt;/cfoutput&gt;
&lt;cfsetting enablecfoutputonly=&quot;No&quot;&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using HTTPService tag to send/receive variables to a server-side script on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/',contentID: 'post-94',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'lastResult,send()',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/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically creating ActionScript cue points from FlashVars loaded using the HTTPService tag</title>
		<link>http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/</link>
		<comments>http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/#comments</comments>
		<pubDate>Sun, 12 Aug 2007 17:28:00 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[addCuePoint()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/</guid>
		<description><![CDATA[<p>In a previous post, <a href="http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/">&#8220;Dynamically creating ActionScript cue points from FlashVars received from the HTML container&#8221;</a>, we looked at how to create ActionScript cue points based on variables passed in to our Flex application from the HTML template&#8217;s &#8220;FlashVars&#8221; parameter. In this post we look at a similar approach, although using the &#60;mx:HTTPService /&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, <a href="http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/">&#8220;Dynamically creating ActionScript cue points from FlashVars received from the HTML container&#8221;</a>, we looked at how to create ActionScript cue points based on variables passed in to our Flex application from the HTML template&#8217;s &#8220;FlashVars&#8221; parameter. In this post we look at a similar approach, although using the &lt;mx:HTTPService /&gt; tag to load cue points from an external file of name/value pairs. This example could easily be extended further to pass a variable to a server-side script which would grab cue point information from a database and pass it back into Flex either as a string of name/value pairs, or as an XML document.</p>
<p>Full code after the jump.</p>
<p><span id="more-82"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_dynamic_cuePoint_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="httpService.send()"&gt;

    &lt;mx:HTTPService id="httpService"
            url="cuepoints.txt"
            result="httpService_result(event)"
            resultFormat="flashvars" /&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.events.VideoEvent;
            import mx.collections.ArrayCollection;
            import mx.events.CuePointEvent;
            import mx.managers.SystemManager;
            import mx.utils.URLUtil;
            import mx.utils.ObjectUtil;

            [Bindable]
            private var arrColl:ArrayCollection = new ArrayCollection();

            private function httpService_result(evt:ResultEvent):void {
                var flashVars:Object = httpService.lastResult;

                var item:String;
                for (item in flashVars) {
                    videoDisplay.cuePointManager.addCuePoint({name:item, time:flashVars[item]});
                }
            }

            private function videoDisplay_cuePoint(evt:CuePointEvent):void {
                var cpDate:Date = new Date(evt.cuePointTime * 1000);
                arrColl.addItem({name:evt.cuePointName, time:dateFormatter.format(cpDate)});
            }

            private function videoDisplay_playheadUpdate(evt:VideoEvent):void {
                var pDate:Date = new Date(evt.playheadTime * 1000 || 10);
                var tDate:Date = new Date(evt.currentTarget.totalTime * 1000);
                progressBar.setProgress(evt.playheadTime, evt.currentTarget.totalTime);
                progressBar.label = dateFormatter.format(pDate) + " / " + dateFormatter.format(tDate);
            }

            private function videoDisplay_progress(evt:ProgressEvent):void {
                progressBar.conversion = 1024; /* Convert bytes to kilobytes. */
                progressBar.label = "%1 of %2 KB (%3%%)";
                progressBar.setProgress(evt.bytesLoaded, evt.bytesTotal);
            }

            private function videoDisplay_click(evt:MouseEvent):void {
                videoDisplay.play();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:DateFormatter id="dateFormatter" formatString="NN:SS" /&gt;

    &lt;mx:HBox&gt;
        &lt;mx:Canvas&gt;
            &lt;mx:VideoDisplay id="videoDisplay"
                    autoPlay="false"
                    autoRewind="false"
                    source="http://www.helpexamples.com/flash/video/water.flv"
                    cuePointManagerClass="mx.controls.videoClasses.CuePointManager"
                    cuePoint="videoDisplay_cuePoint(event)"
                    playheadUpdate="videoDisplay_playheadUpdate(event)"
                    progress="videoDisplay_progress(event)"
                    click="videoDisplay_click(event)"
                    rewind="arrColl=new ArrayCollection()"
                    rollOver="progressBar.visible = true"
                    rollOut="progressBar.visible = false" /&gt;

            &lt;mx:ProgressBar id="progressBar"
                    mouseChildren="false"
                    labelPlacement="center"
                    visible="false"
                    mouseEnabled="false"
                    mode="manual" left="5" right="5" bottom="5" /&gt;
        &lt;/mx:Canvas&gt;

        &lt;mx:DataGrid id="dataGrid"
                height="100%"
                dataProvider="{arrColl}"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="name"
                        headerText="CuePoint Name:" /&gt;
                &lt;mx:DataGridColumn dataField="time"
                        headerText="CuePoint Time:" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:HBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download">cuepoints.txt</p>
<pre class="code">
one=1&amp;two=2&amp;three=3
</pre>
<p>For each name/value pair in the cuepoints.txt file, the name is mapped to the cue point name, and the value is the number of seconds to create the ActionScript cue point at.</p>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_dynamic_cuePoint_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_dynamic_cuePoint_test_2/bin/main.html" width="100%" height="310"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Dynamically creating ActionScript cue points from FlashVars loaded using the HTTPService tag on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/',contentID: 'post-82',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'addCuePoint()',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/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically creating ActionScript cue points from FlashVars received from the HTML container</title>
		<link>http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/</link>
		<comments>http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 04:45:57 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[addCuePoint()]]></category>
		<category><![CDATA[URLUtil.stringToObject()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/</guid>
		<description><![CDATA[<p>In a previous post, <a href="http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/">&#8220;Creating ActionScript cue points with the VideoDisplay controlEdit&#8221;</a>, reader Florian asks how you can set cue points dynamically from FlashVars.</p> <p>Well, here&#8217;s one method of passing a single name/value pair from the HTML template into our Flex application and having Flex parse the string and dynamically add the ActionScript cue [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, <a href="http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/">&#8220;Creating ActionScript cue points with the VideoDisplay controlEdit&#8221;</a>, reader Florian asks how you can set cue points dynamically from FlashVars.</p>
<p>Well, here&#8217;s one method of passing a single name/value pair from the HTML template into our Flex application and having Flex parse the string and dynamically add the ActionScript cue points to the VideoDisplay control.</p>
<p>Hope that helps.</p>
<p>Full code after the jump.</p>
<p><span id="more-76"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_dynamic_cuePoint_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" applicationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.events.VideoEvent;
            import mx.collections.ArrayCollection;
            import mx.events.CuePointEvent;
            import mx.managers.SystemManager;
            import mx.utils.URLUtil;
            import mx.utils.ObjectUtil;

            [Bindable]
            private var arrColl:ArrayCollection;

            private function init():void {
                arrColl = new ArrayCollection();

                var cpObj:Object;

                var item:String;
                var itemArr:Array;
                var params:Object = Application.application.parameters;
                if (params.hasOwnProperty("cuepoints")) {
                    cpObj = URLUtil.stringToObject(params.cuepoints);
                    for (item in cpObj) {
                        itemArr = item.split(":");
                        videoDisplay.cuePointManager.addCuePoint({name:itemArr[0], time:Number(itemArr[1])});
                    }
                }
            }

            private function videoDisplay_cuePoint(evt:CuePointEvent):void {
                var cpDate:Date = new Date(evt.cuePointTime * 1000);
                arrColl.addItem({name:evt.cuePointName, time:dateFormatter.format(cpDate)});
            }

            private function videoDisplay_playheadUpdate(evt:VideoEvent):void {
                var pDate:Date = new Date(evt.playheadTime * 1000 || 10);
                var tDate:Date = new Date(evt.currentTarget.totalTime * 1000);
                progressBar.setProgress(evt.playheadTime, evt.currentTarget.totalTime);
                progressBar.label = dateFormatter.format(pDate) + " / " + dateFormatter.format(tDate);
            }

            private function videoDisplay_progress(evt:ProgressEvent):void {
                progressBar.conversion = 1024; /* Convert bytes to kilobytes. */
                progressBar.label = "%1 of %2 KB (%3%%)";
                progressBar.setProgress(evt.bytesLoaded, evt.bytesTotal);
            }

            private function videoDisplay_click(evt:MouseEvent):void {
                videoDisplay.play();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:DateFormatter id="dateFormatter" formatString="NN:SS" /&gt;

    &lt;mx:HBox&gt;
        &lt;mx:Canvas&gt;
            &lt;mx:VideoDisplay id="videoDisplay"
                    autoPlay="false"
                    autoRewind="false"
                    source="http://www.helpexamples.com/flash/video/water.flv"
                    cuePointManagerClass="mx.controls.videoClasses.CuePointManager"
                    cuePoint="videoDisplay_cuePoint(event)"
                    playheadUpdate="videoDisplay_playheadUpdate(event)"
                    progress="videoDisplay_progress(event)"
                    click="videoDisplay_click(event)"
                    rewind="arrColl=new ArrayCollection()"
                    rollOver="progressBar.visible = true"
                    rollOut="progressBar.visible = false" /&gt;

            &lt;mx:ProgressBar id="progressBar" mouseChildren="false"
                    labelPlacement="center"
                    visible="false"
                    mouseEnabled="false"
                    mode="manual" left="5" right="5" bottom="5" /&gt;
        &lt;/mx:Canvas&gt;

        &lt;mx:DataGrid id="dataGrid"
                height="100%"
                dataProvider="{arrColl}"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="name"
                        headerText="CuePoint Name:" /&gt;
                &lt;mx:DataGridColumn dataField="time"
                        headerText="CuePoint Time:" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:HBox&gt;

&lt;/mx:Application&gt;
</pre>
<p>And in my HTML I add the following FlashVars string to my AC_FL_RunContent function:</p>
<pre class="code" lang="javascript">
AC_FL_RunContent(
    &quot;src&quot;, &quot;main&quot;,
    &quot;width&quot;, &quot;100%&quot;,
    &quot;height&quot;, &quot;100%&quot;,
    &quot;align&quot;, &quot;middle&quot;,
    &quot;id&quot;, &quot;main&quot;,
    &quot;quality&quot;, &quot;high&quot;,
    &quot;bgcolor&quot;, &quot;#ffffff&quot;,
    &quot;name&quot;, &quot;main&quot;,
    &quot;allowScriptAccess&quot;,&quot;sameDomain&quot;,
    &quot;type&quot;, &quot;application/x-shockwave-flash&quot;,
    &quot;pluginspage&quot;, &quot;http://www.adobe.com/go/getflashplayer&quot;,
    <b style="color:red;">&quot;FlashVars&quot;, &quot;cuepoints=one:1;two:2;three:3&quot;</b>
);
</pre>
<p>We&#8217;re passing a single name/value pair where the name is &#8220;cuepoints&#8221; and the value is a set of three cue points with the syntax &#8220;&lt;cuePointName /&gt;:&lt;cuePointTime /&gt; and each cue point is separated by a &#8220;;&#8221;. So, our first cue point is given a name of &#8220;one&#8221; at 1.0 seconds, the second cue point has a name of &#8220;two&#8221; at 2.0 seconds, and the final cue point is &#8220;three&#8221; at 3.0 seconds.</p>
<p>In our Flex application these cue points are separated out using the <code>URLUtil.stringToObject()</code> method, and the <code>Array.split()</code> method.</p>
<p class="information">View source is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_dynamic_cuePoint_test/bin/main.html" width="100%" height="300"></iframe></p>
<p>Happy Flexing!</p>
<p class="new">For another example of creating cue points dynamically see <a href="http://blog.flexexamples.com/2007/08/12/dynamically-creating-actionscript-cue-points-from-flashvars-loaded-using-the-httpservice-tag/">&#8220;Dynamically creating ActionScript cue points from FlashVars loaded using the HTTPService tag&#8221;</a> which uses an HTTPService tag to load a text file of name/value pairs which get converted to new ActionScript cue points.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Dynamically creating ActionScript cue points from FlashVars received from the HTML container on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/',contentID: 'post-76',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'addCuePoint(),URLUtil.stringToObject()',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/09/dynamically-creating-actionscript-cue-points-from-flashvars-received-from-the-html-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

