我正在玩弄新的 youtube as3 API,但被卡住了。这就是我得到的(通过查看他们的示例代码)。
public class Main extends Sprite
{
Security.allowDomain("*");
private var player:Object;
private var loader:Loader;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}
private function onLoaderInit(e:Event):void
{
addChild(loader);
loader.contentLoaderInfo.addEventListener("onReady", onPlayerReady);
loader.contentLoaderInfo.addEventListener("onError", onPlayerError);
loader.contentLoaderInfo.addEventListener("onStateChange", onPlayerStateChange);
loader.contentLoaderInfo.addEventListener("onPlayerQualityChange", onVideoPlaybackQualityChange);
}
private function onPlayerReady(e:Event):void
{
trace("Player ready: " + Object(e).Data);
}
private function onPlayerError(e:Event):void
{
trace("Player error: " + Object(e).Data);
}
private function onPlayerStateChange(e:Event):void
{
trace("Player state: " + Object(e).Data);
}
private function onVideoPlaybackQualityChange(e:Event):void
{
trace("Video quality: " + Object(e).Data);
}
}
我真的不知道下一步是什么。我没有收到任何错误,也没有任何东西被追踪。我很确定我的事件没有正确实施。
更新:我按照 Amarghosh 的回答做了这个:
private function onLoaderInit(e:Event):void
{
player = Sprite(loader.content);
addChild(player);
player.addEventListener("onReady", onPlayerReady);
player.addEventListener("onError", onPlayerError);
player.addEventListener("onStateChange", onPlayerStateChange);
player.addEventListener("onPlayerQualityChange", onVideoPlaybackQualityChange);
}
现在 onPlayerReady 和 onStateChange 事件触发,但我得到错误。跟踪 Object(e).Data 时出现此错误
ReferenceError: Error #1069: the property Data was not found for com.google.youtube.event.ExternalEvent and there is no standard value.
(从瑞典语翻译)当更改为 Object(e.target).Data 时,它会跟踪“未定义”,而 Object(e.target) 会跟踪 [object SwfProxy]。
如果我尝试player.loadVideoById("uad17d5hR5s");
我会收到此错误:
1061: Call to a possibly undefined method loadVideoById through a reference with static type flash.display:Sprite.