// The player SWF file on www.youtube.com needs to communicate with your host // SWF file. Your code must call Security.allowDomain() to allow this // communication. Security.allowDomain("www.youtube.com"); // This will hold the API player instance once it is initialized. var player:Object; var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); //load the embedded player play_btn.addEventListener(MouseEvent.CLICK, playVid); pause_btn.addEventListener(MouseEvent.CLICK, pauseVid); video1_btn.addEventListener(MouseEvent.CLICK,playVid1); video2_btn.addEventListener(MouseEvent.CLICK,playVid2); video3_btn.addEventListener(MouseEvent.CLICK,playVid3); mute_btn.addEventListener(MouseEvent.CLICK,muteVideo); unmute_btn.addEventListener(MouseEvent.CLICK,unmuteVideo); function onLoaderInit(event:Event):void { addChild(loader); loader.content.addEventListener("onReady", onPlayerReady); loader.content.addEventListener("onError", onPlayerError); loader.content.addEventListener("onStateChange", onPlayerStateChange); loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange); } function onPlayerReady(event:Event):void { // Event.data contains the event parameter, which is the Player API ID trace("player ready:", Object(event).data); player = loader.content; player.loadVideoByUrl("http://www.youtube.com/v/v6oJ5rw9mys",0); // Set appropriate player dimensions an its position player.setSize(480, 360); player.x=50; player.y=220; video_title.text="Multiplying Sevens-Times Table"; } function onPlayerError(event:Event):void { // Event.data contains the event parameter, which is the error code trace("player error:", Object(event).data); } function onPlayerStateChange(event:Event):void { // Event.data contains the event parameter, which is the new player state trace("player state:", Object(event).data); } function onVideoPlaybackQualityChange(event:Event):void { // Event.data contains the event parameter, which is the new video quality trace("video quality:", Object(event).data); } |