Prev: Flash Video
Next: Language
From: Robert Crowe on
I'm trying to embed FLV videos from YouTube into a Flash cast member and
sprite. YouTube has an ActionScript 2 API for their player and I'm using
Director 11 and Flash CS 3.

http://code.google.com/apis/youtube/flash_api_reference.html

I need to pull them from YouTube, I can't download them to disk and then use
them.

I can embed a movie with a normal FLVplayer component and get it to play video
from the net. Lingo really isn't doing anything here. The ActionScript looks
like this (CODE SNIPPET 1):

But using the YouTube player I need to use their API, so the code looks like
this (CODE SNIPPET 2).

When I test the movie in Shockwave it loads the player and
ytplayer.isPlayerLoaded returns true, but the video does not play.

Does anyone have any ideas what the problem might be? I think I'm close ...

CODE SNIPPET 1
--------------
import mx.video.*;
my_FLVPlybk.autoPlay = false;
var listenerObject:Object = new Object();
listenerObject.ready = function(eventObject:Object):Void {
my_FLVPlybk.seekSeconds(4);
my_FLVPlybk.play();
};
my_FLVPlybk.addEventListener("ready", listenerObject);
my_FLVPlybk.contentPath = "http://www.helpexamples.com/flash/video/water.flv";


CODE SNIPPET 2
--------------
// create a MovieClip to load the player into
dbg("creating ytplayer");
ytplayer = createEmptyMovieClip("ytplayer", 1);

// create a listener object for the MovieClipLoader to use
ytPlayerLoaderListener = {};
var loadInterval:Number;

// When the player clip first loads, we start an interval to check for when the
// player is ready
ytPlayerLoaderListener.onLoadInit = function() {
loadInterval = setInterval(checkPlayerLoaded, 250);
}

function checkPlayerLoaded():Void {
// once the player is ready, we can subscribe to events, or in the case of
// the chromeless player, we could load videos
if (ytplayer.isPlayerLoaded()) {
ytplayer.addEventListener("onStateChange", onPlayerStateChange);
ytplayer.addEventListener("onError", onPlayerError);
loadIndicator._visible = false;
clearInterval(loadInterval);
}
}

function onPlayerStateChange(newState:Number) {
trace("New player state: " + newState);
}

function onPlayerError(errorCode:Number) {
trace("An error occurred: " + errorCode);
}

// create a MovieClipLoader to handle the loading of the player
ytPlayerLoader = new MovieClipLoader();
ytPlayerLoader.addListener(ytPlayerLoaderListener);

// load the player
ytPlayerLoader.loadClip("http://www.youtube.com/v/Hz8p6VaZK8I", ytplayer);

From: Robert Crowe on
Got it working:

http://www.ourwebhome.com/dig/you/yt1.htm

I used Shane's excellent AS2 API from:

http://www.lostinactionscript.com/blog/index.php/2007/10/13/flash-you-tube-api/

The only thing I had to add was some code to initialize the sprite:

property spriteNum
on beginSprite
fs = sprite(spriteNum)
fs.actionsEnabled = TRUE
fs.buttonsEnabled = TRUE
fs.eventPassMode = #passAlways
end


 | 
Pages: 1
Prev: Flash Video
Next: Language