我在
上收到错误 1120访问未定义属性knop_stop.addEventListener(MouseEvent.CLICK,stopVideos);
我想要9个按钮,播放视频。触发视频时,将显示一个按钮以退出视频,因此当您按下另一个按钮时可以播放另一个视频。
import fl.video.*;
import flash.events.MouseEvent;
stop();
knop_1.addEventListener(MouseEvent.CLICK,speel1);
knop_2.addEventListener(MouseEvent.CLICK,speel2);
knop_3.addEventListener(MouseEvent.CLICK,speel3);
knop_4.addEventListener(MouseEvent.CLICK,speel4);
knop_5.addEventListener(MouseEvent.CLICK,speel5);
knop_6.addEventListener(MouseEvent.CLICK,speel6);
knop_7.addEventListener(MouseEvent.CLICK,speel7);
knop_8.addEventListener(MouseEvent.CLICK,speel8);
knop_9.addEventListener(MouseEvent.CLICK,speel9);
knop_stop.addEventListener(MouseEvent.CLICK,stopVideos);
knop_stop.visible=false;
var videoArray:Array = new Array(
"video/video01.flv",
"video/video02.flv",
"video/video03.flv",
"video/video04.flv",
"video/video05.flv",
"video/video06.flv",
"video/video07.flv",
"video/video08.flv",
"video/video09.flv"
);
var filmAan = false;
function speel1(evtObj:MouseEvent):void {
trace("knop 1: video 1");
if (filmAan == false) {
var myVideo1:FLVPlayback = new FLVPlayback();
myVideo1.source = videoArray[0];
addChild(myVideo1);
myVideo1.x=340;
myVideo1.y=227;
myVideo1.width=1360;
myVideo1.height=908;
filmAan = true;
knop_stop.visible=true;
function stopVideos(evtObj:MouseEvent):void {
removeChild(myVideo1);
}
} else {
knop_stop.visible = false;
}
}
我做错了什么?
答案 0 :(得分:1)
如果您希望事件处理程序看到它,您需要将stopVideos函数放在speel1函数之外。将函数放在另一个函数中时,您将内部函数的范围限制为父函数。如果你想让stopVidoes函数对其他任何东西都可见,试试这个:
function speel1(evtObj:MouseEvent):void {
trace("knop 1: video 1");
if (filmAan == false) {
var myVideo1:FLVPlayback = new FLVPlayback();
myVideo1.source = videoArray[0];
addChild(myVideo1);
myVideo1.x=340;
myVideo1.y=227;
myVideo1.width=1360;
myVideo1.height=908;
filmAan = true;
knop_stop.visible=true;
} else {
knop_stop.visible = false;
}
}
function stopVideos(evtObj:MouseEvent):void {
removeChild(myVideo1);
}
答案 1 :(得分:0)
将stopVideos
函数放在speel1
函数体外,并在该函数之外定义myVideo1
:
var myVideo1:FLVPlayback = new FLVPlayback();
addChild(myVideo1);
function speel1(evtObj:MouseEvent):void {
trace("knop 1: video 1");
if (filmAan == false) {
myVideo1.source = videoArray[0];
myVideo1.x=340;
myVideo1.y=227;
myVideo1.width=1360;
myVideo1.height=908;
filmAan = true;
knop_stop.visible=true;
} else {
knop_stop.visible = false;
}
}
function stopVideos(evtObj:MouseEvent):void {
removeChild(myVideo1);
}