PDA

View Full Version : Listener to stop FLV w/ mouseEvent.Click


Mabron
05-22-2008, 01:07 AM
First of all, I am somewhat newish to Flash AS3...I come from a video editing/design background so please forgive me...

I have a flash player (Player 1) that has a XML gallery on Frame ONE of my AS3 project.

Then i have a second player (Player 2) and library associated with that player living on Frame 2...All works great!

Except...

When the user selects the standard navigation button to go to the Next category (Frame 2, Player 2) in effect Frame 2 of the main time line...The player on Frame 1 continues to play and buffer, so you can hear it under the new frame/Player 2...

What is the best approach to stop this from happening...Obviously it is distracting and taxes the bandwidth ect...

function playMyFlv(){
_stream.close();
if(autoStart == "true" || is_single_file == false)
{
//player_paused = false;
toolbar.btn_play.dispatchEvent(new Event("mouseDown"));
} else {
autoStart = "true";
if(is_single_file == true){
getSingleImage();
big_play_btn.x = bg.width/2 - big_play_btn.width/2;
big_play_btn.y = bg.height/2 - big_play_btn.height/2;
big_play_btn.visible = true;
}
}
first_run=false;
toolbar.checkPlayButton();
}

function onMetaData(data:Object){
first_run=false;
if(contains(single_image_holder))removeChild(singl e_image_holder);
_timer.start();
_duration = data.duration;
_stream.soundTransform = toolbar.videoVolume;
toolbar.btn_volume.getVolume();
//resizeVideo();
}

function onNetStatus(e:NetStatusEvent){
//trace(e.info.code);
//this resets the player on movie end
if(e.info.code == "NetStream.Play.Stop"){
toolbar.resetMovie(new Event("e"));
first_run=true;
toolbar.alpha = 1;
}
if(e.info.code == "NetStream.Play.Start"){
_video.attachNetStream(_stream);
show_buffer = true;
}

if(e.info.code == "NetStream.Buffer.Empty"){
show_buffer = true;
}
if(e.info.code == "NetStream.Buffer.Full"){
show_buffer = false;
}

console.appendText(e.info.code);
resizeVideo();
}

function onTimer(t:TimerEvent){
toolbar.showTimerProgress();
toolbar.showLoaded();
toolbar.showStats();
playerTimer();
}

//set timer text
function playerTimer(){
var _minutes = Math.floor(_stream.time/60);
var _seconds = Math.floor(_stream.time - (_minutes * 60));
if(_minutes < 10) _minutes = "0"+_minutes;
if(_seconds < 10) _seconds = "0"+_seconds;

var d_minutes = Math.floor(_duration/60);
var d_seconds = Math.floor(_duration - (d_minutes * 60));
if(d_minutes < 10) d_minutes = "0"+d_minutes;
if(d_seconds < 10) d_seconds = "0"+d_seconds;

toolbar.player_timer.htmlText = _minutes +":" + _seconds + " / <font color='#dddddd'>" + d_minutes +":" + d_seconds + "</font>";

if(show_buffer == true){
var percent = _stream.bufferLength * 100/_stream.bufferTime;
toolbar.buffer_preloader.visible = true;
toolbar.buffer_preloader.preloader.rotate_(percent );
} else {
toolbar.buffer_preloader.visible = false;
}
}

///Buffers and sizes the FLV///

function createVideoInstance(){
_video = new Video(bg.width, bg.height);

connection = new NetConnection();
connection.connect(null);

Client = new Object();
Client.onMetaData = onMetaData;

_stream = new NetStream(connection);
_stream.addEventListener(NetStatusEvent.NET_STATUS , onNetStatus);
_stream.client = Client;
_stream.bufferTime = 3;
_stream.bufferLength
_video.attachNetStream(_stream);
addChild(_video);
swapChildren(_video, toolbar);
}

function resizeVideo(){
_video.width = _video.videoWidth;
_video.height = _video.videoHeight;
////
var sx:Number = 1;
var sy:Number = 1;

if(bg.width != _video.width)sx = bg.width/_video.width;
_video.width = bg.width;
_video.height = _video.height * sx;
if(resizeMode == "fitScreen"){
if(_video.width > bg.width){
sx = bg.width/_video.width;
_video.width = bg.width;
_video.height = _video.height * sx;
}
if(_video.height > bg.height){
sy = bg.height/_video.height;
_video.height = bg.height;
_video.width = _video.width * sy;
}
} else {
if(_video.height < bg.height){
sy = bg.height/_video.height;
_video.height = bg.height;
_video.width = _video.width * sy;
}
}

console.appendText("sx = " + sx.toString()+ " " + " sy= "+ sy.toString() + " video : "+ _video.width );

_video.x = bg.width/2 - _video.width/2;
_video.y = bg.height/2 - _video.height/2;
video_mask.width = bg.width;
video_mask.height = bg.height;
}


////Standard Button Navagation/////

mograph_btn.addEventListener(MouseEvent.CLICK, navigate2);

function navigate2(event)
{
gotoAndPlay("mograph");
}

ANY Direction would be fantastic...I am not sure how to handle this.

Kindly,
Matt