Youtube Player Loader Class in AS2
Just a little class that I made this week to load the youtube flash player in a flash. This class is made in action script 2 with the help of the pixlib.
import com.bourre.commands.Delegate;
import com.bourre.events.BasicEvent;
import com.bourre.events.EventType;
import com.bourre.events.NumberEvent;
import com.bourre.visual.MovieClipHelper;
import com.bourre.commands.CommandManagerMS;
import com.bourre.core.HashCodeFactory;
/**
* @author Rajabaly Nicolas
* @version 0.1
*/
class YoutubeLoader extends MovieClipHelper {
private var _mc:MovieClip;
private var _scale:Number;
private var _commandMs:CommandManagerMS;
private var _delCheckPlayer:Delegate;
private var _mcl:MovieClipLoader;
private var _listener:Object;
//
static public var LOAD_START:EventType = new EventType("onLoadYoutubePlayerStart");
static public var LOAD_PROGRESS:EventType = new EventType("onLoadYoutubePlayerProgress");
static public var LOAD_COMPLETE:EventType = new EventType("onLoadYoutubePlayerComplete");
static public var PLAYER_IS_READY:EventType = new EventType("onYoutubePlayerReady");
static public var PLAYERLOADER_IS_OPEN:EventType = new EventType("onYoutubeLoaderOpen");
static public var PLAYERLOADER_IS_CLOSE:EventType = new EventType("onYoutubeLoaderClose");
public function YoutubeLoader(name:String, mc:MovieClip) {
super(name, mc);
_commandMs = CommandManagerMS.getInstance();
_delCheckPlayer = new Delegate(this, _checkPlayer);
System.security.allowDomain("http://youtube.com");
}
private function _checkPlayer():Void{
if (_mc.isPlayerLoaded()) {
_commandMs.remove(_delCheckPlayer);
_mc._alpha=100;
_mc._xscale = _mc._yscale = _scale;
_oEB.dispatchEvent(new BasicEvent(PLAYER_IS_READY));
}
}
private function _loadProgressPlayer(myTarget:MovieClip, myBytesLoaded:Number, myBytesTotal:Number):Void {
var myPrcent:Number = Math.round(myBytesLoaded / myBytesTotal * 100);
_oEB.dispatchEvent(new NumberEvent(LOAD_PROGRESS, myPrcent));
}
private function _loadCompletePlayer():Void {
_oEB.dispatchEvent(new BasicEvent(LOAD_COMPLETE));
_commandMs.delay(_delCheckPlayer, 250);
}
private function _loadStartPlayer():Void {
_oEB.dispatchEvent(new BasicEvent(LOAD_START));
}
public function open(myId:String, myScale:Number):Void {
_scale = myScale;
_mc = view.createEmptyMovieClip(HashCodeFactory.getNextName(), 1);
_mc._alpha=0;
_mcl = new MovieClipLoader();
_listener = new Object();
_listener.onLoadStart = Delegate.create(this, _loadStartPlayer);
_listener.onLoadProgress = Delegate.create(this, _loadProgressPlayer);
_listener.onLoadInit = Delegate.create(this, _loadCompletePlayer);
_mcl.addListener(_listener);
_mcl.loadClip("http://youtube.com/v/" + myId, _mc);
_oEB.dispatchEvent(new BasicEvent(PLAYERLOADER_IS_CLOSE));
}
public function release():Void {
stopAllSounds();
_mc.removeMovieClip();
_mcl.removeListener(_listener);
_oEB.dispatchEvent(new BasicEvent(PLAYERLOADER_IS_OPEN));
super.release();
}
}
To use it in flash :
import YoutubeLoader;
import com.bourre.commands.Delegate;
import com.bourre.events.NumberEvent;
import com.bourre.events.BasicEvent;
var myLoader:YoutubeLoader=new YoutubeLoader("THENAMEOFTHELOADERINSTANCE",this.createEmptyMovieClip("loadertest",this.getNextHighestDepth()));
myLoader.addEventListener(YoutubeLoader.LOAD_START,Delegate.create(this,_loadStart));
myLoader.addEventListener(YoutubeLoader.LOAD_PROGRESS,Delegate.create(this,_loadprogress));
myLoader.addEventListener(YoutubeLoader.LOAD_COMPLETE,Delegate.create(this,_loadComplete));
myLoader.addEventListener(YoutubeLoader.PLAYER_IS_READY,Delegate.create(this,_playerReady));
myLoader.addEventListener(YoutubeLoader.PLAYERLOADER_IS_OPEN,Delegate.create(this,_playerLoaderOpen));
myLoader.addEventListener(YoutubeLoader.PLAYERLOADER_IS_CLOSE,Delegate.create(this,_playerLoaderClose));
myLoader.open("37t52UpCaGE",200);
//myLoader.close();
function _loadStart(e:BasicEvent):Void{
trace("_loadStart");
}
function _loadprogress(e:NumberEvent):Void{
trace("_loadprogress"+e.getNumber());
}
function _loadComplete(e:BasicEvent):Void{
trace("_loadComplete");
}
function _playerReady(e:BasicEvent):Void{
trace("_playerReady");
}
function _playerLoaderOpen(e:BasicEvent):Void{
trace("_playerLoaderOpen");
}
function _playerLoaderClose(e:BasicEvent):Void{
trace("_playerLoaderClose");
}
Enjoy ![]()
Tips: Embed fonts and Input Textfield focus
Anoying thing with dynamic input textfields in AS3: when adding the field in your stage without text, there’s no way to have any focus on it.
_field.type = TextFieldType.INPUT; _field.selectable = true; _field.embedFonts = true; var format:TextFormat = new TextFormat(); format.font = "Myriad Pro"; format.size = 12; format.color = 0x000000; _field.antiAliasType=AntiAliasType.ADVANCED; _field.setTextFormat(format); addChild(_field);
Result: Impossible to put text in it.
A part of the solution is to insert text before adding the field to the parent object.
_field.text="some text"; addChild(_field);
You got it, focus is there, but you also have this very unusefull text.
To resolve this problem, I used the Event.ADDED_TO_STAGE to clear text content.
_field.addEventListener(Event.ADDED_TO_STAGE, onAdd);
//then the listener handler
private function onAdd(evt:Event):void {
evt.currentTarget.text = "";
}
Here you have a clean input textfield, with an embed font, mouse and tab focus. Cool hu ?
Make some noise
An indie project leaded by the well known developer Andre Michelle. Make some noise is a campaign calling from Adobe to fix some serious problems with sound API of the last Flash Player versions and to rally people support to show Adobe that people wants more controls over sound for the next Flash Player issues.
Nice goal, indeed.
Support it: http://www.make-some-noise.info
PHP6, Unicode and TextIterator features
I’ve just install the last version of PHP6 dev and I’ve decided to test the famous new feature, the PHP Unicode Support. I will not explain new things about PHP6 or Unicode or TextIterator, it’s just my discoveries test on this features.
So the first thing to do is to enable PHP6 Unicode in the php.ini file.
;;;;;;;;;;;;;;;;;;;; ; Unicode settings ; ;;;;;;;;;;;;;;;;;;;;unicode.semantics = on unicode.runtime_encoding = utf-8 unicode.script_encoding = utf-8 unicode.output_encoding = utf-8 unicode.from_error_mode = U_INVALID_SUBSTITUTE unicode.from_error_subst_char = 3f
3D Air Graffiti
Tagged in Motion from Psyxonaut on Vimeo.
Very impressive installation called Tagged in motion. The artist draws a 3d graf using a virtual spray can and googles. The motion is recorded by 3 cameras and an open source software, ArtToolKit
Cool result.
About
This is the R&D corner of Nicolas Rajabaly, Antoine Ughetto and Jonathan Da Costa. Enjoy it.
Lab : Check it
You want to be a contributor?!
Send a mail to :
antoine _AT_ makemepulse _DOT_ com

