2

我收到错误1120 access of undefined property on

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

}

我做错了什么?

4

2 回答 2

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);          
}
于 2012-12-10T22:12:01.230 回答
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);          
        }
于 2012-12-11T09:08:55.400 回答