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” layout=“vertical”
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #000000]"
creationComplete=“service.send()” viewSourceURL=“srcview/index.html”>
<mx:Style>
ComboBox {
color: #000000;
selectionColor: #ffffff;
rollOverColor: #cccccc;
textRollOverColor: #000000;
themeColor: #000000;
}
</mx:Style>
<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";
}
]]>
</mx:Script>
<mx:HTTPService id="service" url="data.xml" result="resultHandler(event)"/>
<mx:VideoDisplay id="videoDisplay" width="320" height="240"/>
<mx:ComboBox>
<mx:ArrayCollection>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
<mx:String>AR</mx:String>
</mx:ArrayCollection>
prompt="Select a video ..." dataProvider="{videos}"
labelField="title" change="playVideo(event)" width="165"
</mx:ComboBox>
/*
<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