Adobe Flash - 访问可能未定义 属性 完成

Adobe Flash - Access of possible undefined property COMPLETE

我想在 Flash 中循环播放一些视频,我找到了这段代码,但是当我尝试 运行 时得到了 "Access of possible undefined property COMPLETE through a reference with static type Class"。

video.source="video.flv";
import fl.video.*;
function onFLVCOMPLETE(event:VideoEvent):void{
            event.target.play();
}
video.addEventListener(VideoEvent.COMPLETE, onFLVCOMPLETE);

不知道发生了什么,所以任何帮助都是很好的

编辑

这是正在发生的事情:

FlashPro/AdobeAnimate IDE 自动导入 flash.events 包(无论您是否明确告知)。当它执行此操作时,flash.events.VideoEvent class 将替换您导入的 fl.video.VideoEvent class 作为您使用 VideoEvent 时引用的内容。

要解决这个问题,您只需使用完全限定的 class 名称。所以不要使用:

 VideoEvent

您使用:

fl.video.VideoEvent

因此您的代码应如下所示:

function onFLVCOMPLETE(event:fl.video.VideoEvent):void{
            event.target.play();
}
video.addEventListener(fl.video.VideoEvent.COMPLETE, onFLVCOMPLETE);

要测试此行为,您在时间轴上使用以下代码创建一个新的 FlashPro 项目:(您还需要将视频组件添加到库中)

import fl.video.VideoEvent;
trace(flash.utils.getQualifiedClassName(VideoEvent));

输出window中的预期结果是fl.video::VideoEvent,但实际结果是:

flash.events::VideoEvent

所以即使您只导入了 fl.video.VideoEventVideoEvent 指的是 flash.events.VideoEvent(未导入)。