<?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; addCuePoint()</title>
	<atom:link href="http://blog.flexexamples.com/tag/cuepointmanager-addcuepoint/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>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>
	</channel>
</rss>

