Search code examples
flashactionscriptloopsflvnetstream

action script, flash, ns - loop a flv if a condition is true


Good day to all.

I need to loop a flv file in flash if a condition is true.

So I tryed to add a listener but id doesn't work.. Code below:

textBox.addEventListener(FocusEvent.FOCUS_IN, focusInListener);

var connection:NetConnection = new NetConnection(); 
var stream:NetStream; 
var video:
Video = new Video(200, 200); 
var metaObj:Object = new Object();

function onMetaData(data:Object):void {

}

var checkvid=0;

connection.connect(null); 
stream = new NetStream(connection); 
stream.client = metaObj; 
metaObj.onMetaData = onMetaData; 
video.attachNetStream(stream); 
addChild(video); 
stream.play("Mann ft. 50 Cent - Buzzin 2010-(mrsjs).flv"); 
video.x = 0; 
video.y = 40;

textBox.addEventListener(KeyboardEvent.KEY_DOWN,handler);

function handler(event:KeyboardEvent)
{     
   if(event.charCode == 13) // if the key is ENTER
   {
      switch (textBox.text)
     {
       case "1": 
               stream.play("m1.flv");  
               checkvid=0;
               // Note from Slomojo - You probably wanted a break; here.
           case "2": 
               stream.play("m2.flv");
               checkvid=1; 
               break;
           case "3": 
               stream.play("m3.flv");
               checkvid=0; 
               break;
     }
    }
}

var listener:Object = new Object();
listener.complete = function():Void {
   stream.seek(0);
   stream.play();
}
stream.addEventListener("complete", listener);

Any idea is appreciated. Thank you.


Solution

  • NetStream doesn't fire a complete event, and you're doing the listener object incorrectly, you use a direct callback function for the NetStream

    See here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#event:onPlayStatus

    Basically, you listen to onStatus - assign a callback to it... ie:

    stream_ns.onStatus = function(infoObject:Object) {
            trace("NetStream.onStatus called: ("+getTimer()+" ms)");
            for (var prop in infoObject) {
                trace("\t"+prop+":\t"+infoObject[prop]);
            }
    };
    

    The information you want is in the infoObject.