我正在尝试从我的Player.as发送自定义YouTubeEvent并希望我的Main.as会监听并创建视频播放器......显然我的eventHandler无法捕捉事件来创建视频播放器..... ..我的flex调试模式是如此搞砸我甚至无法使用它...我的代码如下..我非常感谢任何回复或帮助......
我的自定义活动..
package com.youtube.events {
import flash.events.Event;
public class YouTubeEvent extends Event{
public static const PLAYER_READY:String="PLAYER_READY";
public function YouTubeEvent(type:String){
super(type);
}
}
}
My Main.as
public class SearchYoutube extends Sprite
{
private var videoPlayer:Player;
public function SearchYoutube()
{
/*********************Load Video Player****************************/
loadPlayer();
}
private function loadPlayer():void{
videoPlayer= new Player();
videoPlayer.addEventListener(YouTubeEvent.PLAYER_READY, playerReady);
//playReady would never be excuted....
}
private function playerReady(event:YouTubeEvent):void{
videoPlayer.createPlayer(); //This handler would never be executed...
addChild(videoPlayer); //This handler would never be executed...
}
}
Player.as
//only show part of codes here
public function Player(){
}
public function createPlayer():void{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
}
private function onLoaderInit(event:Event):void {
_loader.content.addEventListener("onReady", onPlayerReady);
}
private function onPlayerReady(event:Event):void {
dispatchEvent(new YouTubeEvent(YouTubeEvent.PLAYER_READY));
}
答案 0 :(得分:2)
YouTubeEvent.PLAYER_READY
后, createPlayer()
会被调度一段时间。您应该在createPlayer()
之后致电videoPlayer.addEventListener(YouTubeEvent.PLAYER_READY, playerReady)
:
private function loadPlayer():void
{
videoPlayer= new Player();
videoPlayer.addEventListener(YouTubeEvent.PLAYER_READY, playerReady);
videoPlayer.createPlayer();
}
答案 1 :(得分:1)
This简短教程将为您提供使用Flex自定义事件的正确途径。