# Small problem with video

**URL:** <https://forum.kirupa.com/t/small-problem-with-video/263282>\
**Category:** Uncategorized\
**Created:** [June 14, 2008, 12:09am UTC](https://forum.kirupa.com/t/small-problem-with-video/263282 "2008-06-14T00:09:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rotarypot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rotarypot/32/1289_2.png) [@rotarypot](https://forum.kirupa.com/u/rotarypot)\
**Post date:** [June 14, 2008, 12:09am UTC](https://forum.kirupa.com/t/small-problem-with-video/263282/1 "2008-06-14T00:09:41Z")

</div>

hi everyone:

i’m working on a site that will use a 3 seg flv video as an intro, short and sweet.

first i load a still image which actually is the first frame from the video, then, after that is finished loading, it gets added to the display list.  
after that is done i preload the flv video, so far so good …

the problem resides in that when i click on the blue button to actually begin playback of the video and “enter” the site, there seems to be a slight delay in the playback of the video leaving the stage empty for a split second.

i guess that it’s better if you look at it …

[this is the url](http://www.fotografika.com.mx/sitio2008/principal.html)

this is the class i’m using  
thanks for any help !!

```auto

package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.Sprite;
import flash.text.*;
import flash.events.*;
import flash.net.URLRequest;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.net.*;
import flash.media.Video;
import flash.display.SimpleButton;

public class principal extends MovieClip { 
			/* definamos variables and stuff */
 			var photoLoader:Loader;
           	var videoConnection:NetConnection = new NetConnection();
			var videoLoader:URLLoader = new URLLoader();
			var videoStream:NetStream;
		
/ ******************************** /
public function principal():void{ // esta funcion es la que se ejecuta por default cuando carga el movie
	
	startButton.addEventListener(MouseEvent.CLICK, playIntro);
	
	
	
		/* setup del video */ 
		videoConnection.connect(null);
		videoStream = new NetStream(videoConnection);
		videoStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
		videoStream.addEventListener(NetStatusEvent.NET_STATUS, netstat);
		var client:Object = new Object();
		client.onMetaData = onMetaData;
		videoStream.client = client;
		/* creamos el objeto de video*/
		var video:Video = new Video(960, 610);
		video.attachNetStream(videoStream);
		/* agregamos al display list*/
		video.x = 31; video.y = 79; /* posicionamos el video */
		addChild(video);
		photoLoader = new Loader();
	photoLoader.load(new URLRequest("imagenes/intro-still.jpg")); // creamos el URLRequest definiendo que queremos cargar.
   	photoLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, cargaProgresando); // ahi vamos cargando 
	photoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, cargaCompleta); // terminando de cargar el still, sigue el video  
} /* end principal */
				
		
		
/* funciones and ****e************************** /
function videoProgress(event:ProgressEvent):void {
		var percent:Number = Math.floor( (event.bytesLoaded*100)/event.bytesTotal );
		if (percent > 90) { /*mostramos el enter button*/ }
		loadDisplay2.text = percent+"%";
}

function playIntro(event:MouseEvent):void {
		
		videoStream.play("intro-video.flv"); /* iniciamos el playback del video previamente cargado */
		removeChild(photoLoader);
}

function cargaProgresando(event:ProgressEvent):void {
		var percent:Number = Math.floor( (event.bytesLoaded*100)/event.bytesTotal );
		loadDisplay.text = percent+"%";
}

function cargaCompleta(event:Event):void { 
		/* fade out load display*/
		var myTween:Tween = new Tween(loadDisplay, "y", Strong.easeOut, loadDisplay.y, loadDisplay.y-40, 1, true);
		var myTween2:Tween = new Tween(loadDisplay, "alpha", Strong.easeOut, 1, 0, 1, true);
		myTween2.addEventListener(TweenEvent.MOTION_FINISH, showStill); 
} 

function showStill (e:TweenEvent):void{
		/* setup still*/
		this.photoLoader.alpha = 0;
		this.photoLoader.x = 31;photoLoader.y = 79; // posicionamos el still
		this.addChild(photoLoader);
		var myTween4:Tween = new Tween(photoLoader, "alpha", Strong.easeOut, 0, 1, 1, true);/* fade in still */
		/* video */
		videoLoader.addEventListener(ProgressEvent.PROGRESS, videoProgress); /* checamos el progreso del video */
		videoLoader.load( new URLRequest("intro-video.flv")); /* comienza la descarga del video pero no lo mostramos todavia. */ 
}

function asyncErrorHandler(event:AsyncErrorEvent):void {
		trace(event.text);
}

function netstat(stats:NetStatusEvent) {
		trace(stats.info.code);
		if(stats.info.code == "NetStream.Play.Stop") {trace("video finished")}
}

function onMetaData(data:Object):void { trace(data.duration + " seconds long");}

} /* close class */
} /* close package*/

```

---

<div class="post-metadata">

**Author:** ![rotarypot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rotarypot/32/1289_2.png) [@rotarypot](https://forum.kirupa.com/u/rotarypot)\
**Post date:** [June 14, 2008, 1:15am UTC](https://forum.kirupa.com/t/small-problem-with-video/263282/2 "2008-06-14T01:15:44Z")

</div>

aha!!  
solved!!

i need it to set a listener for the video stream  
…

this is the code in case anyone finds this useful…

```auto

package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.Sprite;
import flash.text.*;
import flash.events.*;
import flash.net.URLRequest;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.net.*;
import flash.media.Video;
import flash.display.SimpleButton;

public class principal extends MovieClip { 
			/* definamos variables and stuff */
 			var photoLoader:Loader;
           	var videoConnection:NetConnection = new NetConnection();
			var videoLoader:URLLoader = new URLLoader();
			var videoStream:NetStream;
		
/ ******************************** /
public function principal():void{ // esta funcion es la que se ejecuta por default cuando carga el movie
	
	startButton.addEventListener(MouseEvent.CLICK, playIntro);
		
		/* setup del video */ 
		videoConnection.connect(null);
		videoStream = new NetStream(videoConnection);
		videoStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
		videoStream.addEventListener(NetStatusEvent.NET_STATUS, netstat);
		var client:Object = new Object();
		client.onMetaData = onMetaData;
		videoStream.client = client;
		/* creamos el objeto de video*/
		var video:Video = new Video(960, 610);
		video.attachNetStream(videoStream);
		/* agregamos al display list*/
		video.x = 31; video.y = 79; /* posicionamos el video */
		addChild(video);
		photoLoader = new Loader();
	photoLoader.load(new URLRequest("imagenes/intro-still.jpg")); // creamos el URLRequest definiendo que queremos cargar.
   	photoLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, cargaProgresando); // ahi vamos cargando 
	photoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, cargaCompleta); // terminando de cargar el still, sigue el video  
} /* end principal */
				
		
		
/* funciones and ****e************************** /
function videoProgress(event:ProgressEvent):void {
		var percent:Number = Math.floor( (event.bytesLoaded*100)/event.bytesTotal );
		if (percent > 90) { /*mostramos el enter button*/ }
		loadDisplay2.text = percent+"%";
}

function playIntro(event:MouseEvent):void {
		
		videoStream.play("intro-video.flv"); /* iniciamos el playback del video previamente cargado */
		
}

function cargaProgresando(event:ProgressEvent):void {
		var percent:Number = Math.floor( (event.bytesLoaded*100)/event.bytesTotal );
		loadDisplay.text = percent+"%";
}

function cargaCompleta(event:Event):void { 
		/* fade out load display*/
		var myTween:Tween = new Tween(loadDisplay, "y", Strong.easeOut, loadDisplay.y, loadDisplay.y-40, 1, true);
		var myTween2:Tween = new Tween(loadDisplay, "alpha", Strong.easeOut, 1, 0, 1, true);
		myTween2.addEventListener(TweenEvent.MOTION_FINISH, showStill); 
} 

function showStill (e:TweenEvent):void{
		/* setup still*/
		this.photoLoader.alpha = 0;
		this.photoLoader.x = 31;photoLoader.y = 79; // posicionamos el still
		this.addChild(photoLoader);
		var myTween4:Tween = new Tween(photoLoader, "alpha", Strong.easeOut, 0, 1, 1, true);/* fade in still */
		/* video */
		videoLoader.addEventListener(ProgressEvent.PROGRESS, videoProgress); /* checamos el progreso del video */
		videoLoader.load( new URLRequest("intro-video.flv")); /* comienza la descarga del video pero no lo mostramos todavia. */ 
}

function asyncErrorHandler(event:AsyncErrorEvent):void {
		trace(event.text);
}

function netstat(stats:NetStatusEvent) {
		trace(stats.info.code);
		

		if (stats.info.code == "NetStream.Play.Start"){ removeChild(photoLoader); trace("video started")}
	
		if(stats.info.code == "NetStream.Play.Stop") {trace("video finished")}
}

function onMetaData(data:Object):void { trace(data.duration + " seconds long");}

} /* close class */
} /* close package*/

```
