0

基本上我有一个非常简单的视频库设置。我想要它,这样当视频暂停时,一些按钮将在屏幕上可见,而在播放时这些按钮将不可见。这是我的代码:

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;
4

2 回答 2

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,这没关系,因为无论如何您都不需要该参数。

于 2016-02-23T22:30:48.953 回答
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。

于 2016-02-24T15:54:41.583 回答