基本上我设置了一个非常简单的视频库。我想要它,以便当视频暂停时,屏幕上会显示一些按钮,当它播放时,这些按钮将不可见。这是我的代码:
import fl.video.*;
import fl.video.VideoEvent;
import flash.events.Event;
videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo());
videoOne.addEventListener(Event.PAUSED_STATE_ENTERED, showInfo());
function showInfo() {
thumbnailOne.visible = true;
thumbnailTwo.visible = true;
thumbnailThree.visible = true;
videoGalleryInfo.visible = true;
infoHidden = 0;
}
function hideInfo() {
thumbnailOne.visible = false;
thumbnailTwo.visible = false;
thumbnailThree.visible = false;
videoGalleryInfo.visible = false;
infoHidden = 1;
}
我尝试使用Event而不是VideoEvent等,因为这修复了早先为COMPLETE事件添加另一个事件监听器的问题,但我总是返回
Video gallery, Layer 'ActionScript', Frame 77, Line 22 1119: Access of possibly undefined property PLAYING_STATE_ENTERED through a reference with static type Class.
Video gallery, Layer 'ActionScript', Frame 77, Line 23 1119: Access of possibly undefined property PAUSED_STATE_ENTERED through a reference with static type Class.
我不明白我做错了什么。不应该通过导入fl.video来定义属性。*;和flash.events.Event;?
编辑:如果它很重要,这是我特定场景的其余代码,包括null建议的修复。我仍然得到相同的错误,加上" 1136:不正确的参数数量。预计1"错误
import flash.events.MouseEvent;
import fl.video.*;
import fl.video.VideoEvent;
import flash.events.Event;
stop();
homeButton.addEventListener(MouseEvent.CLICK, homePressed);
soundButton.addEventListener(MouseEvent.CLICK, soundPressed);
helpButton.addEventListener(MouseEvent.CLICK, helpPressed);
exitButton.addEventListener(MouseEvent.CLICK, exitPressed);
var videoPlaying:int = 0;
var infoHidden:int = 0;
videoOne.addEventListener(Event.COMPLETE, vid1Comp);
function vid1Comp(event:Event) {
videoOne.visible = false;
showInfo();
}
videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, showInfo);
function showInfo(e:Event):void {
thumbnailOne.visible = true;
thumbnailTwo.visible = true;
thumbnailThree.visible = true;
videoGalleryInfo.visible = true;
infoHidden = 0;
}
function hideInfo(e:Event):void {
thumbnailOne.visible = false;
thumbnailTwo.visible = false;
thumbnailThree.visible = false;
videoGalleryInfo.visible = false;
infoHidden = 1;
}
thumbnailOne.addEventListener(MouseEvent.CLICK, playVid1);
function playVid1(event:MouseEvent) {
hideInfo();
if (musicPlaying == 1) {
SoundMixer.stopAll();
musicPlaying = 0;
}
videoOne.visible = true;
videoOne.play();
videoPlaying = 1;
}
videoOne.visible = false;
答案 0 :(得分:0)
此行调用函数hideInfo
:
videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo());
但它应该传递函数(而不是调用它),如下所示:
videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo);
您要添加的事件类型的常量在VideoEvent
类中定义,因此实际代码应如下所示:
videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
函数的签名应该是回调的签名。它应该采用类型Event
的单个参数或其适当的子类:
function hideInfo(e:Event):void {
您也可以
function hideInfo(e:VideEvent):void {
但是你无论如何都没有使用参数,所以有'没有必要进一步专门化这种类型。
我仍然得到相同的错误,加上" 1136:参数数量不正确。预计1"错误
那是因为你改变了我建议的功能的签名。 在没有任何参数的情况下调用函数时:
showInfo();
这会导致您收到的错误。
为了避免这种情况,因为您没有在这些函数中使用参数,您可以再次更改该函数以接受参数的默认值null
:
function showInfo(e:Event = null):void {
这种方式如果在没有参数的情况下调用,则参数默认为null
,这是可以的,因为您无论如何都不需要参数。
答案 1 :(得分:0)
我发现要解决此问题,您必须使用事件的完整路径,因此更改
videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, showInfo);
到
videoOne.addEventListener(fl.video.VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(fl.video.VideoEvent.PAUSED_STATE_ENTERED, showInfo);
修好了。很简单,真的。谢谢你的帮助,无论如何,@ null。