Selteco.com > FlashDesignerZONE.com > Tutorials > T1090

Insert YouTube in Flash

How to load and display YouTube movie in Alligator Flash Designer project.

The link to the movie usually looks like this

www.youtube.com/watch?v=5RFxGn6C6ak

If you know the link you can easily insert the movie to your Flash animation.

  1. Launch Alligator Flash Designer
  2. Draw a Sprite

  3. Inside the Sprite choose Frame > ActionScript
  4. Paste the code below and adjust the name of the movie, in this case 5RFxGn6C6ak

    System.security.allowDomain("http://www.youtube.com");
    System.security.loadPolicyFile("http://www.youtube.com/crossdomain.xml");

    loadMovie("http://www.youtube.com/v/5RFxGn6C6ak");

  5. Click OK
  6. Press F9 to run the movie

If yuo want to resize the movie after it has been loaded YouTube use the following commands:

_xscale = 50;
_yscale = 50;

where 50 means 50% of original size. Download source project t1090.zip (5 kb)

Inserting 2 or more YouTube videos

If you place more than one YouTube video and jump between frames, the movie will not stop automatically. To prevent playing 2 or more movies at the same time you have to execute ActionScript commands to stop all videos at the beginning of each frame. Choose Frame > ActionScript and enter the code:
Sprite1.stopVideo();
Sprite2.stopVideo();
Sprite3.stopVideo();
where Sprite1, Sprite2 i Sprite3 are inserted YouTube videos.

How to control YouTube video in Flash project

Use the following commands (in this example the movie placeholder is Sprite1):

Sprite1.playVideo();
Starts video playback

Sprite1.pauseVideo();
Pauses video playback and buffering continues

Sprite1.stopVideo();
Stops video playback and data buffering

Sprite1.destroy();
Removes video from the project and releases memory

Sprite1.clearVideo();
Removes the last visible frame of the movie after is has been stopped

Sprite1.seekTo(seconds:Number, allowSeekAhead:boolean);
Scrolls the movie to specified second, if allowSeekAhead is true the movie will start buffering from specified second

Sprite1.mute();
Switches the sound off

Sprite1.unMute();
Switches the sound on

Sprite1.isMuted():boolean;
Returns true is sound is off

Sprite1.getVolume():Number;
Returns sound volume from 0 to 100

Sprite1.setVolume(volume:Number);
Sets sound volume from 0 to 100

Sprite1.setSize(width:Number, height:Number);
Sets size of the movie in pixels

Sprite1.getVideoBytesLoaded():Number;
Returns number of bytes buffered so far

Sprite1.getVideoBytesTotal():Number;
Returns total size of the movie in bytes

Sprite1.getPlayerState():Number;
Returns current status of the player: unstarted (-1), ended (0), playing (1), paused (2), buffering (3), cued (5).

Sprite1.getCurrentTime():Number;
Returns current second

Sprite1.setPlaybackQuality(quality:String);
Sets video quality and size of the player is the movie is available in this version

Sprite1.getPlaybackQuality():String;
Returns current size and quality of the movie after it has been started

Sprite1.setPlaybackQuality("small");
Sets player size 240 pixels high

Sprite1.setPlaybackQuality("medium");
Sets player size 360 pixels high

Sprite1.setPlaybackQuality("large");
Sets player size 480 pixels high

Sprite1.setPlaybackQuality("hd720");
Sets player size 720 pixels high (HD)

Sprite1.setPlaybackQuality("hd1080");
Sets player size 1080 pixels high (Full HD)

Sprite1.setPlaybackQuality("default");
Sets default player size and quality

Sprite1.getVideoUrl():String;
Returns current Url of the movie

Sprite1.getDuration():Number;
Returns total time of the movie in seconds after the video has been started

Sprite1.getVideoEmbedCode():String;
Returns HTML code required to insert video in a web page

Download source project with YouTube controls t1090a.zip (5 kb)

Products | Purchase | Downloads | Support | Flash Tutorials | Contact | Privacy Policy | Avoid Piracy | Jobs
Copyright © 1999-2011 Selteco Software, 1821 Walden Office Square, Schaumburg, IL 60173, Ph: +1-800-490-0407