Actionscript Youtube API问题-Can';我看不到录像

Actionscript Youtube API问题-Can';我看不到录像,actionscript,youtube,youtube-api,Actionscript,Youtube,Youtube Api,我对youtube actionscript api有问题。。。问题是,你可以看到播放按钮和加载标志,你可以听到视频的声音,但你看不到 为什么呢 代码如下: // myPlayer.as package { import flash.display.*; import flash.events.*; import flash.ui.*; import flash.net.*; public class myPlayer extends MovieClip

我对youtube actionscript api有问题。。。问题是,你可以看到播放按钮和加载标志,你可以听到视频的声音,但你看不到

为什么呢

代码如下:

// myPlayer.as
package {
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    import flash.net.*;
    public class myPlayer extends MovieClip {
        var player:Object;
        var loader:Loader;
        public function myPlayer() {
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
            loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
            //loader.load(new URLRequest("http://www.youtube.com/v/O8vcyOKYH9g?enablejsapi=1&playerapiid=ytplayerx=400"));
            x=300;
            y=300;


        }

        function onLoaderInit(event:Event):void {
            addChild(loader);
            //loader.x+=loader.width/2;
            //loader.y+=loader.height/2;
            loader.content.addEventListener("onReady", onPlayerReady);
            loader.content.addEventListener("onError", onPlayerError);
            loader.content.addEventListener("onStateChange", onPlayerStateChange);
            loader.content.addEventListener("onPlaybackQualityChange", 
                    onVideoPlaybackQualityChange);
        }

        function onPlayerReady(event:Event):void {
            // Event.data contains the event parameter, which is the Player API ID 
            trace("player ready:", Object(event).data);

            // Once this event has been dispatched by the player, we can use
            // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
            // to load a particular YouTube video.
            player=loader.content;
            player.cueVideoById("O8vcyOKYH9g", 0, "default");
            //player.cueVideoByUrl("http://www.youtube.com/watch?v=2ekLO8BwxwE", 0, "default");}
        }
        function onPlayerError(event:Event):void {
            // Event.data contains the event parameter, which is the error code
            trace("player error:", Object(event).data);
        }

        function onPlayerStateChange(event:Event):void {
            // Event.data contains the event parameter, which is the new player state
            trace("player state:", Object(event).data);
        }

        function onVideoPlaybackQualityChange(event:Event):void {
            // Event.data contains the event parameter, which is the new video quality
            trace("video quality:", Object(event).data);
        }

    }
}

// main.as

package {
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    import flash.net.*;
    public class main extends MovieClip {
        var m:myPlayer;
        public function main() {
            m=new myPlayer();
            addChild(m);
        }

    }
}

非常感谢你

我也遇到了同样的问题,在通过URL调用视频之前,使用API的player.setSize(w,h)方法可以在Flex 3.5中正确显示视频:

Object( ytSwfLoader.content ).setSize( 300, 300 );
if ( vidsArr[ currVid ].indexOf( 'youtube.com' ) != -1 ) Object( ytSwfLoader.content ).loadVideoByUrl( vidsArr[ currVid ]);
还要注意的是,youtube API文档说loadVideoByUrl()方法不适用于AS3(仅Javascript),并且只有cueVideoByURL()可以工作,但上面的代码确实加载并播放了视频