ActionScript3で動画をループさせる(Video,NetStreamクラス)

ActionScript3の疑似ストリーミング(プログレッシブダウンロード)を使う場合に
ループ再生はありがちだと思います。(個人的に)

以下、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;
				// ↓停止したら再生を行う
				case "NetStream.Play.Stop":
					stream.play(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.
		}
	}
}

[ 参考 ]
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Video.html


NetStream.Play.Stopが再生終了時に発生するのでこんな感じで、また再生してやれば出来ます。



NetStream.Play.Completeは、疑似ストリーミングの場合返されないようです。