Hello guys, I’m new in as3, so if I say or if I did something stupid in my code, please bear with me!
I have been making some “application” in as3/flash for some customer… let me explain what, that application is supposed to do:
It should load a video, and as the video runs, I should be able to add some dynamic content, such as pictures and audio. I searched on internet for a similar code, but I couldn’t find anything, so the way I “solved it” is with a timer. Whenever the timer is at an specific moment the script fires or includes a file.
The problem is that the netstream and the timer never start at the same time, and that makes very difficult to add anything at the exact moment I want . Here is my code:
var param:Object = LoaderInfo(this.root.loaderInfo).parameters;
var sexo;
var nombre;
var edad;
var aptitudes;
var problemas;
sexo = param["var1"];
nombre = param["var2"];
edad = param["var3"];
aptitudes = param["var4"];
problemas = param["var5"];
var firstName:Sound=new Sound();
firstName.load(new URLRequest("audios/"+ nombre +".mp3"));
var imageLoader:Loader = new Loader();
var pic:URLRequest = new URLRequest("nino.jpg");
imageLoader.load(pic);
imageLoader.visible = false;
imageArea.addChild(imageLoader);
var imageFirma:Loader = new Loader();
var Firma:URLRequest = new URLRequest("image.jpg");
imageFirma.load(Firma);
imageName.addChild(imageFirma);
Reproducir.visible = false;
var src = "7.flv",
videoLoader:URLLoader = new URLLoader(),
video:Video = new Video(720, 480);
videoLoader.addEventListener(ProgressEvent.PROGRESS , VideoLoading);
videoLoader.addEventListener(Event.COMPLETE , VideoLoaded);
videoLoader.load(new URLRequest(src));
function VideoLoading(e:ProgressEvent):void{
trace(e.bytesLoaded/e.bytesTotal);
var loaded:Number = e.bytesLoaded / e.bytesTotal;
preloader.SetProgress(loaded);
}
function VideoLoaded(e:Event):void{
var con:NetConnection = new NetConnection();
con.connect(null);
var stream:NetStream = new NetStream(con),
meta:Object = new Object();
stream.addEventListener(NetStatusEvent.NET_STATUS , StreamStatus);
stream.bufferTime = 10;
function StreamStatus(stat:Object):void{
if(stat.info.code == "NetStream.Play.Stop")
{
stream.seek(0);
}
}
var t:Timer = new Timer(1000);
t.addEventListener(TimerEvent.TIMER, onTick);
function onTick(event:TimerEvent):void {
var nsSecs:Number = Math.floor(stream.time);
var nsMins:Number = Math.floor(nsSecs / 60);
nsMins %= 60;
nsSecs %= 60;
var nsSecsDisplay:String = "";
var nsMinsDisplay:String = "";
if (nsMins < 10){
nsMinsDisplay = "0" + nsMins;
} else {
nsMinsDisplay = "" + nsMins;
}
if (nsSecs < 10){
nsSecsDisplay = "0" + nsSecs;
} else {
nsSecsDisplay = "" + nsSecs;
}
time_txt.text = nsMinsDisplay + ":" + nsSecsDisplay;
if(nsSecsDisplay == '04' && nsMinsDisplay == "00"){
firstName.play();
}
if(nsSecsDisplay >= '26' && nsSecsDisplay <= '30'){
imageLoader.visible = true;
}else{
imageLoader.visible = false;
}
}
stream.client = meta;
preloader.visible = false;
Reproducir.visible = true;
addChildAt(video, 0);
video.attachNetStream(stream);
Reproducir.addEventListener(MouseEvent.CLICK, onMouseDownhandler);
function onMouseDownhandler (event:Event):void {
Reproducir.visible = false;
stream.play(src);
t.start();
}
}
Any help will be very much appreciate! Thanks in advance!