Question

Hello im doing a presentation that has some videos on it. To watch the videos i have made some buttons and i found a code to bring the external videos to stage. The problem is that when i go to the next frame the last video stays there. This is the code i have to set the videos on the stage:

miguel_btn.addEventListener(MouseEvent.CLICK,video_miguel);
function video_miguel(event:MouseEvent):void
{
var conexion10:NetConnection= new NetConnection();
conexion10.connect(null);
var display10:NetStream= new NetStream(conexion10);
display10.play("Miguel_1.flv");
var video10:Video=new Video();
video10.attachNetStream(display10);
video10.x= 150;
video10.y= 250;
stage.addChild(video10);
display10.addEventListener(AsyncErrorEvent.ASYNC_ERROR,nomostrar10);
function nomostrar10(event:AsyncErrorEvent):void
{
}
} 

and i was trying to removing them with :

if (event.keyCode == Keyboard.RIGHT)
{
        nextFrame();
                video10.clear();
}

but i am a new at as3 and it does not work. Thanks.

Was it helpful?

Solution

Since you didn't post the entire code it is difficult to determine the problem. I believe the issue lies in problem that your keyboard event is not firing. I would recommend trying the following code to see if it resolves your problem.

Instead of calling video10.clear(); I removed the object entirely as well.

import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.net.NetConnection;
import flash.media.Video;
import flash.net.NetStream;

miguel_btn.addEventListener(MouseEvent.CLICK, video_miguel);
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

var video10:Video;
var display10:NetStream;

function video_miguel(event:MouseEvent):void {

    display10 = new NetStream(new NetConnection());
    display10.play("Miguel_1.flv");

    video10 = new Video();
    video10.attachNetStream(display10);
    video10.x = 150;
    video10.y = 250;

    stage.addChild(video10);
}

function handleKeyDown(ke:KeyboardEvent):void {
    //keycode 39 is the right arrow key.
    if(ke.keyCode == 39) {
        nextFrame();
    //We can completely remove the video by calling the function below.
        stage.removeChild(video10);
    }
}

OTHER TIPS

I agree with Andreas, and I would suggest to close netStream and still clear the video:

display10.close();
video10.clear();
stage.removeChild(video10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top