AS3 Video MouseEvent单击无法正常工作

时间:2011-10-10 00:58:20

标签: flash actionscript-3 events click mouseevent

我创建了一个简单的视频,我尝试将鼠标单击事件附加到它,但事件不会触发。这是我的代码:

var connection:NetConnection;
var stream:NetStream;
var video:Video;

connection = new NetConnection();
connection.connect(null);

stream = new NetStream(connection);
stream.client = this;

video = new Video(425, 320);
stage.addChild(video);


video.attachNetStream(stream);

stream.bufferTime = 1;

stream.receiveAudio(true);
stream.receiveVideo(true);

stream.play("freshprince.flv");

video.addEventListener(MouseEvent.CLICK, function() {

    trace("Video Clicked");                                                
});

它有什么问题以及为什么鼠标事件不起作用?

1 个答案:

答案 0 :(得分:2)

将视频放入movieClip并将事件添加到movieClip

video = new Video(425, 320);
var mc:MovieClip = new MovieClip();
mc.addChild(video);
stage.addChild(mc);

mc.addEventListener(MouseEvent.CLICK, function() {
  trace("Video Clicked");                                                
});

注意:Video类不是InteractiveObject类的子类,因此无法分派鼠标事件。但是,您可以在包含Video对象的显示对象容器上调用addEventListener()方法。 (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Video.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6)