Hi, My situation: - viewStack (creationPolicy=all) - canvas - canvas - - hbox - - canvas - - customVideoPlayerComponent - - - hbox - - - canvas (id=holder)
I want to play youtube video's in a chromeless player. I'm using this Youtube AS3 wrapper: http://www.ovidiudiac.ro/blog/2009/03/youtube-as3-wrapper/ My steps are as follows: - Create loader - Load the wrapper swf - Create new UIComponent - Add loader to UIComponent - Add UIComponent to canvas (id=holder) Everything's working except for one thing: When I re-size the browser, another instance of the player is loaded and shown above my current player. This only happens when the video is partly offscreen. This is weird, since the traces from the method that loads the player aren't being called. I've added the source below, but here's the entire project for your convenience: http://www.dauntless.be/Temp/Youtubetest.rar Somewhere, somehow the Canvas/Viewstack/loader is redrawn (without removing the previous one ? :s) and I really don't understand why & how... All help is appreciated! I've I'm not clear enough, please let me know. Source: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" xmlns:local="*"> <mx:ViewStack id="stack" selectedIndex="1"> <mx:Canvas id="canv1"/> <mx:Canvas> <local:VideoPlayer/> </mx:Canvas> </mx:ViewStack> </mx:Application> <?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"> <mx:Canvas id="holder" width="500" height="400"/> <mx:HBox> <mx:Button label="Pause" click="pause(event);" id="lblPause"/> <mx:Button label="Play Next" click="playNext(event);"/> <mx:Button label="Like it" click="likeIt(event);"/> <mx:Button label="Hate it" click="hateIt(event);"/> </mx:HBox> <mx:Script> <![CDATA[ import pinosh.youtube.YoutubeEvent; import pinosh.youtube.IYoutube; import mx.core.UIComponent; private var player:IYoutube; private var ldr:Loader; private var paused:Boolean = false; private function pause(e:Event):void { if(paused) { player.playVideo(); lblPause.label = "Pause"; } else { lblPause.label = "Play"; player.pauseVideo(); } paused = !paused; } private function playNext(e:Event):void { } private function likeIt(e:Event):void { } private function hateIt(e:Event):void { } public function loadVideo(e:String):void { player.loadVideo(e); } private function init():void { trace("init"); ldr = new Loader(); ldr.load(new URLRequest("ytPlayer.swf")); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onPlayerLoaded); ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onPlayerLoadError); } private function onPlayerLoaded(e:Event):void { ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, onPlayerLoaded); ldr.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onPlayerLoadError); trace("onPlayerLoaded"); this.player = ldr.content as IYoutube; player.addEventListener(YoutubeEvent.PLAYER_READY, onPlayerReady); player.addEventListener(YoutubeEvent.PLAYER_ERROR, onPlayerError); player.addEventListener(YoutubeEvent.PLAYER_STATE_CHANGE, onPlayerStateChange); //if(!this.player.isPlayerReady()) //{ this.player.destroyAndReload(); //} var uicomp:UIComponent = new UIComponent(); holder.addChild(uicomp); uicomp.addChild(ldr); } private function onPlayerLoadError():void { trace("Kon youtube swf niet laden"); } private function onPlayerError(e:YoutubeEvent):void { trace("player error: "+player.getPlayerError()); } private function onPlayerStateChange(e:Event):void { trace("State change"); } private function onPlayerReady(event : YoutubeEvent) : void { trace("player ready"); // maybe set the size player.setSize(500, 400); player.loadVideo("Phyg_uIPQII"); } ]]> </mx:Script> </mx:VBox>

