{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.system.LoaderContext;
import flash.text.TextField;
import flash.net.URLRequest;
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.system.ApplicationDomain;
/**
* ...
* @author
*/
public class Main extends Sprite
{
public var mousePos:TextField;
public var player:Object;
public var loader:Loader;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
drawBackground();
}
private function drawBackground():void
{
var bg:Sprite = new Sprite();
bg.graphics.beginFill(0xeeeeee);
bg.graphics.drawRect(0, 0, 800, 600);
this.addChild(bg);
addMousePosLabel();
}
private function addMousePosLabel():void
{
mousePos = new TextField();
mousePos.text = "initialized";
mousePos.x = 10;
mousePos.y = 10;
this.addChild(mousePos);
initializeTracking();
}
private function initializeTracking():void
{
this.addEventListener(MouseEvent.MOUSE_MOVE, updateMousePos);
initializeVideo();
}
private function updateMousePos(me:MouseEvent):void
{
var output:String = "x: " + this.mouseX + " | y: " + this.mouseY;
mousePos.text = output;
}
private function initializeVideo():void
{
Security.allowDomain("*");
var context:LoaderContext = new LoaderContext();
//context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = new ApplicationDomain();
var url:URLRequest = new URLRequest("http://www.youtube.com/apiplayer?version=3");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(url,context);
}
private function onLoaderInit(event:Event):void {
loader.x = 10;
loader.y = 40;
this.addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onError", onPlayerError);
loader.content.addEventListener("onStateChange", onPlayerStateChange);
loader.content.addEventListener("onPlaybackQualityChange",
onVideoPlaybackQualityChange);
}
private function onPlayerReady(event:Event):void {
// Event.data contains the event parameter, which is the Player API ID
trace("player ready:", Object(event).data);
// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
player = loader.content;
// Set appropriate player dimensions for your application
player.setSize(480, 360);
}
private function onPlayerError(event:Event):void {
// Event.data contains the event parameter, which is the error code
trace("player error:", Object(event).data);
}
private function onPlayerStateChange(event:Event):void {
// Event.data contains the event parameter, which is the new player state
trace("player state:", Object(event).data);
}
private function onVideoPlaybackQualityChange(event:Event):void {
// Event.data contains the event parameter, which is the new video quality
trace("video quality:", Object(event).data);
}
}
}
Hello everyone!
- Stage is created and skinned
- an event listener is added to the stage to listen for MOUSE_MOVE events and output the global X and Y coordinates of the mouse
- a youtube video is loaded and added to display list following the official method detailed here
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment