Take the 2-minute tour ×

Ive embedded a youtube video into a flash file with different frames for different pages, basically when i click off the page displaying my video, the youtube video is still on screen and the sound carrys on playing. I want the video only to be displayed on one frame, and the sound to stop when i switched frames. Here is my code:


var player : Object;
var mute : Boolean = false;

var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

playButton.addEventListener(MouseEvent.CLICK, playVideo);
pauseButton.addEventListener(MouseEvent.CLICK, pauseVideo);
muteButton.addEventListener(MouseEvent.CLICK, muteVideo);

function onLoaderInit(event:Event):void {
     loader.content.addEventListener("onReady", onPlayerReady); 

function onPlayerReady(event:Event):void {
     player = loader.content;
     player.setSize(520, 265);
     player.x = 230;
     player.y = 370;
     player.cueVideoByUrl("http://www.youtube.com/v/G-P9fO4g2Jc", 0);

function playVideo(event:MouseEvent):void {

function pauseVideo(event:MouseEvent):void {

function muteVideo(event:MouseEvent):void {
        mute = true;
    else {
        mute = false;

Thanks in advance

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The addChild method adds child to the hole movieClip rather than to the currentFrame, actually there isn't way to add child to the give frame.

Possible solutions are:

  1. Create empty sprite in the frame where you need to insert the player and use this sprite as the holder. Don't forget to stop the video when you leave the frame (you can listen the Event.REMOVED_FROM_STAGE event of player for example and stop video in handler).

  2. add onEnterFrame event listener and check the currentFrame property, when it's the target frame add video otherwise remove video.

share|improve this answer
Thanks for that, i managed to make the video play on only one page using a sprite sheet but im still unsure how to stop the sound! –  Awilson089 Jan 17 '13 at 14:08
To stop the sound you need to stop video playback. Add REMOVED_FROM_STAGE event listener to the player: player.addEventListener(Event.REMOVED_FROM_STAGE, onPlayerRemoved) and call player.pauseVideo(); in the onPlayerRemoved –  fsbmain Jan 17 '13 at 14:22

Your Answer


