# Flex/AS3 problem with playing a simple video

**URL:** https://forum.kirupa.com/t/flex-as3-problem-with-playing-a-simple-video/326393
**Category:** Uncategorized
**Created:** [December 11, 2011, 2:31pm UTC](https://forum.kirupa.com/t/flex-as3-problem-with-playing-a-simple-video/326393 "2011-12-11T14:31:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![den372](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@den372](https://forum.kirupa.com/u/den372)
#### Post date: [December 11, 2011, 2:31pm UTC](https://forum.kirupa.com/t/flex-as3-problem-with-playing-a-simple-video/326393/1 "2011-12-11T14:31:33Z")

</div>

Does anyone know how to play a simple video clip using AS3 of flex. At this point I do not want to purchase the flash builder studio. Is it really that complex to do. I only want to play a simple 340x280 vid clip using AS3. I have been trying 2 approaches flex and pure AS3. I am using the mxml compiler the first was a flex approach, the video file name is Video.flv the code is below:

\<?xml version=“1.0” encoding=“utf-8”?\>  
\<mx:Application xmlns:mx=“[http://www.adobe.com/2006/mxml](http://www.adobe.com/2006/mxml)” layout=“vertical”  
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #000000]"  
creationComplete=“service.send()” viewSourceURL=“srcview/index.html”\>

```
 &lt;mx:Style&gt;
 	ComboBox {
	   color: #000000;
	   selectionColor: #ffffff;
	   rollOverColor: #cccccc;
	   textRollOverColor: #000000;
	   themeColor: #000000;
	}
 &lt;/mx:Style&gt;

```

\<mx:Script\>  
\<![CDATA[  
import mx.collections.ArrayCollection;  
import mx.rpc.events.ResultEvent;

```
	[Bindable]
	private var videos : ArrayCollection;
	
	private function resultHandler(event:ResultEvent):void{
		videos = event.result.videolist.video;
	}
	
	private function playVideo(event:Event):void{
		// videoDisplay.source = "assets/" + event.currentTarget.selectedItem.src;

			videoDisplay.source = "assets/Video.flv";
	
	}
	
]]&gt;

```

\</mx:Script\>

```
&lt;mx:HTTPService id="service" url="data.xml" result="resultHandler(event)"/&gt;

&lt;mx:VideoDisplay id="videoDisplay" width="320" height="240"/&gt;

&lt;mx:ComboBox&gt; 
      	&lt;mx:ArrayCollection&gt;
		 &lt;mx:String&gt;AK&lt;/mx:String&gt;
		 &lt;mx:String&gt;AL&lt;/mx:String&gt;
		 &lt;mx:String&gt;AR&lt;/mx:String&gt;
  		&lt;/mx:ArrayCollection&gt;
	prompt="Select a video ..." dataProvider="{videos}" 
	labelField="title" change="playVideo(event)" width="165"

&lt;/mx:ComboBox&gt;

```

/\*  
\<mx:ComboBox\>  
\<mx:ArrayCollection\>  
\<mx:String\>AK\</mx:String\>  
\<mx:String\>AL\</mx:String\>  
\<mx:String\>AR\</mx:String\>  
\</mx:ArrayCollection\>  
\</mx:ComboBox\>

\*/

\</mx:Application\>

I then tried the AS3 solution recommended by adobe:

package {  
import flash.display.Sprite;  
import flash.events.\*;  
import flash.media.Video;  
import flash.net.NetConnection;  
import flash.net.NetStream;

```
public class VideoExample extends Sprite {
    private var videoURL:String = "Video.flv";
    private var connection:NetConnection;
    private var stream:NetStream;

    public function VideoExample() {
        connection = new NetConnection();
        connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        connection.connect(null);
    }

    private function netStatusHandler(event:NetStatusEvent):void {
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                connectStream();
                break;
            case "NetStream.Play.StreamNotFound":
                trace("Unable to locate video: " + videoURL);
                break;
        }
    }

    private function connectStream():void {
        stream = new NetStream(connection);
        stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
        var video:Video = new Video();
        video.attachNetStream(stream);
        stream.play(videoURL);
        addChild(video);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }
    
    private function asyncErrorHandler(event:AsyncErrorEvent):void {
        // ignore AsyncErrorEvent events.
    }
}

```

}

Does anybody in this forum have any idea how to accomplish this without the studio env. Does the code appear incorrect. Any help appreciated
