Saturday, October 24th, 2009
So, give a hand to the developers at YouTube for their hard work! They’ve taken the AS3 YouTube Player out of beta, albeit just chromeless, and all ready for production.
Let’s hope that the chromed version is coming very soon, but now let’s concentrate on getting used to this new player.
Again, to make things simple, I’ve pushed a new class called “YouTubePlayerAS3()” on github that you can use in your application, like so:
{
import com.firestartermedia.lib.as3.display.component.interaction.ButtonSimple;
import com.firestartermedia.lib.as3.display.component.video.YouTubePlayerAS3;
import com.firestartermedia.lib.as3.events.YouTubePlayerEvent;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.system.Security;
[SWF( backgroundColor="#FFFFFF" )]
public class PlayerTest extends Sprite
{
private var player:YouTubePlayerAS3;
public function PlayerTest()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
Security.allowDomain( '*' );
Security.allowDomain( 'www.youtube.com' );
Security.allowDomain( 'youtube.com' );
Security.allowDomain( 's.ytimg.com' );
Security.allowDomain( 'i.ytimg.com' );
init();
}
private function init():void
{
player = new YouTubePlayerAS3();
player.play( 'R7yfISlGLNU' );
addChild( player );
var button:ButtonSimple = new ButtonSimple();
button.buttonText = 'Pause the video';
button.textEmbedFonts = false;
button.draw();
button.addEventListener( MouseEvent.CLICK, handleClick );
addChild( button );
}
private function handleClick(e:MouseEvent):void
{
player.pause();
}
}
}
And without having to play with wrappers or local connections, you have a nice and lovely AS3 YouTube Player in your application! Here’s a demo:
And the fun doesn’t stop there! Now it’s easy to have lots of YouTube Players, like so:
{
import com.firestartermedia.lib.as3.display.component.interaction.ButtonSimple;
import com.firestartermedia.lib.as3.display.component.video.YouTubePlayerAS3;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
[SWF( width="580", height="800", frameRate="24", backgroundColor="#FFFFFF" )]
public class App extends Sprite
{
private var players:Array = [ ];
public function App()
{
var button:ButtonSimple = new ButtonSimple();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
loadAPlayer( 'R7yfISlGLNU', 580, 400 );
loadAPlayer( 'NisCkxU544c', 580, 400, 0, 400 );
button.buttonText = 'Pause the videos';
button.textEmbedFonts = false;
button.draw();
button.addEventListener( MouseEvent.CLICK, handleClick );
addChild( button );
}
private function loadAPlayer(videoId:String, width:Number, height:Number, x:Number=0, y:Number=0):void
{
var player:YouTubePlayerAS3 = new YouTubePlayerAS3();
player.height = height;
player.width = width
player.x = x;
player.y = y;
player.play( videoId );
players.push( player );
addChild( player );
}
private function handleClick(e:MouseEvent):void
{
for each ( var player:YouTubePlayerAS3 in players )
{
player.pause();
}
}
}
}
And this is what you get:
I hope the class helps, tell me what you think.