<?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; connectionError</title>
	<atom:link href="http://blog.flexexamples.com/tag/connectionerror/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>Detecting a connection error when loading an FLV with the VideoDisplay control</title>
		<link>http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/</link>
		<comments>http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 00:57:37 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[VideoEvent]]></category>
		<category><![CDATA[connectionError]]></category>
		<category><![CDATA[stateChange]]></category>
		<category><![CDATA[VideoEvent.CONNECTION ERROR]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/</guid>
		<description><![CDATA[<p>The other day I was playing with the VideoDisplay control in Flex and was curious why my simple test cases were not working. Well, as it turns out, my remote server wasn&#8217;t available so the Flash Video (FLV) couldn&#8217;t be loaded. So I quickly typed up the following code to listen for the stateChange event [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was playing with the VideoDisplay control in Flex and was curious why my simple test cases were not working. Well, as it turns out, my remote server wasn&#8217;t available so the Flash Video (FLV) couldn&#8217;t be loaded. So I quickly typed up the following code to listen for the <code>stateChange</code> event to see if my VideoDisplay control was getting into the dreaded <code>connectionError</code> state (represented by the <code>VideoDisplay.CONNECTION_ERROR</code> constant).</p>
<p>Full code after the jump.</p>
<p><span id="more-19"></span></p>
<p>The following example listens for the <code>stateChange</code> event to determine if the VideoDisplay control entered the <code>VideoEvent.CONNECTION_ERROR</code> state:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_stateChange_connectionError_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/ --&gt;
&lt;mx:Application name="VideoDisplay_stateChange_connectionError_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" &gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;
            import mx.events.VideoEvent;

            private function videoDisplay_stateChange(evt:VideoEvent):void {
                switch (evt.state) {
                    case VideoEvent.CONNECTION_ERROR:
                        evt.currentTarget.visible = false;
                        Alert.show(evt.currentTarget.source, "Unable to connect to video");
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:VideoDisplay id="videoDisplay"
            source="http://www.helpexamples.com/flash/video/404.flv"
            stateChange="videoDisplay_stateChange(event);" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_stateChange_connectionError_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/VideoDisplay_stateChange_connectionError_test/bin/main.html" width="100%" height="200"></iframe></p>
<p>Due to popular demand, here is the &#8220;same&#8221; example in a more ActionScript friendly format:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/VideoDisplay_stateChange_connectionError_test/bin/srcview/source/main2.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/ --&gt;
&lt;mx:Application name="VideoDisplay_stateChange_connectionError_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.VideoDisplay;
            import mx.controls.Alert;
            import mx.events.VideoEvent;

            private var videoDisplay:VideoDisplay;

            private function init():void {
                videoDisplay = new VideoDisplay();
                videoDisplay.addEventListener(VideoEvent.STATE_CHANGE,
                            videoDisplay_stateChange);
                videoDisplay.source = "http://www.helpexamples.com/flash/video/404.flv";
                addChild(videoDisplay);
            }

            private function videoDisplay_stateChange(evt:VideoEvent):void {
                switch (evt.state) {
                    case VideoEvent.CONNECTION_ERROR:
                        evt.currentTarget.visible = false;
                        Alert.show(evt.currentTarget.source, "Unable to connect to video");
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Detecting a connection error when loading an FLV with the VideoDisplay control on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/',contentID: 'post-19',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'connectionError,stateChange,VideoEvent.CONNECTION ERROR',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/07/23/detecting-a-connection-error-when-loading-an-flv-with-the-videodisplay-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

