I need to stop and remove a StageVideo when the user clicks the video. anybody know how to go about doing that?
While the answer may vary depending on implementation, at the most basic level, you'd do something like this where v
is your StageVideo instance:
stage.addEventListener(MouseEvent.CLICK, click);
function click(e:MouseEvent):void {
if(v.viewPort.contains(e.stageX, e.stageY)){
trace("stage video clicked!!!")
}
}
Listen on the stage for a Click event, then see if the x
/y
coordinates of the mouse click are contained in the viewport of the StageVideo
.
Though a more common approach is to put a transparent sprite over the video:
var videoOverlay:Sprite = new Sprite();
videoOverlay.graphics.beginFill(0,0);
videoOverlay.graphics.drawRect(0, 0, v.viewPort.width, v.viewPort.height);
videoOverlay.x = v.viewPort.x;
videoOverlay.y = v.viewPort.y;
addChild(videoOverlay);
videoOverlay.addEventListener(MouseEvent.CLICK, videoClick);
function videoClick(e:MouseEvent):void {
trace("video Clicked");
}