0

您好,我有 2 个错误,我似乎无法解决。虽然看起来应该问题不大。

package  {

import flash.display.MovieClip; //line 3
import flash.events.MouseEvent;


public class video01 extends MovieClip {


    public function video01() {
        // constructor code
        import flash.events.MouseEvent;

        trace("movieclip 1 geladen");

        btn_terug.addEventListener(MouseEvent.CLICK.terug); //line 16


    }


    public function terug(evt:MouseEvent):void {
    trace("knop ingedrukt");

    }


}

}

错误是:第 3 行 1046:找不到类型或不是编译时常量:btn_terug。第 16 行 1119:通过静态类型 String 的引用访问可能未定义的属性 terug。

有什么想法吗?


编辑

这是我的主要代码,它位于 .fla 的时间线上:

import fl.video.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;

stop();

btn_1.addEventListener(MouseEvent.CLICK,speel1);
btn_2.addEventListener(MouseEvent.CLICK,speel2);
btn_3.addEventListener(MouseEvent.CLICK,speel3);
btn_4.addEventListener(MouseEvent.CLICK,speel4);
btn_5.addEventListener(MouseEvent.CLICK,speel5);
btn_6.addEventListener(MouseEvent.CLICK,speel6);
btn_7.addEventListener(MouseEvent.CLICK,speel7);
btn_8.addEventListener(MouseEvent.CLICK,speel8);
btn_9.addEventListener(MouseEvent.CLICK,speel9);


var mc_video01:MovieClip = new video01();
var mc_video02:MovieClip = new video02();
var mc_video03:MovieClip = new video03();
var mc_video04:MovieClip = new video04();
var mc_video05:MovieClip = new video05();
var mc_video06:MovieClip = new video06();
var mc_video07:MovieClip = new video07();
var mc_video08:MovieClip = new video08();
var mc_video09:MovieClip = new video09();

var filmAan = false;

function speel1(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video01);
    mc_video01.x=340; 
    mc_video01.y=227;
    mc_video01.width=1360;
    mc_video01.height=1060;

    filmAan = true;
}
}
function speel2(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video02);
    mc_video02.x=340; 
    mc_video02.y=227;
    mc_video02.width=1360;
    mc_video02.height=1060;

    filmAan = true;
}
}
function speel3(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video03);
    mc_video03.x=340; 
    mc_video03.y=227;
    mc_video03.width=1360;
    mc_video03.height=1060;

    filmAan = true;
}
}
function speel4(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video04);
    mc_video04.x=340; 
    mc_video04.y=227;
    mc_video04.width=1360;
    mc_video04.height=1060;

    filmAan = true;
}
}
function speel5(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video05);
    mc_video05.x=340; 
    mc_video05.y=227;
    mc_video05.width=1360;
    mc_video05.height=1060;

    filmAan = true;
}
}
function speel6(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video06);
    mc_video06.x=340; 
    mc_video06.y=227;
    mc_video06.width=1360;
    mc_video06.height=1060;

    filmAan = true;
}
}
function speel7(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video07);
    mc_video07.x=340; 
    mc_video07.y=227;
    mc_video07.width=1360;
    mc_video07.height=1060;

    filmAan = true;
}
}
function speel8(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video08);
    mc_video08.x=340; 
    mc_video08.y=227;
    mc_video08.width=1360;
    mc_video08.height=1060;

    filmAan = true;
}
}
function speel9(evtObj:MouseEvent):void {
trace("knop 1: video 1");
    if (filmAan == false) {

    addChild(mc_video09);
    mc_video09.x=340; 
    mc_video09.y=227;
    mc_video09.width=1360;
    mc_video09.height=1060;

    filmAan = true;
}
}

主页有 9 个按钮,用于打开带有视频的影片剪辑,以及返回主页的按钮。每个影片剪辑都有一个名为 video01、video02 等的类。(如上所示)它的主 .fla 类的标题为“main”。

主页上的按钮起作用,并且都打开一个不同的影片剪辑(里面有按钮)。我想要做的是让 btn_terug 移除孩子。但我在第 3 行收到错误 1046。

希望这能澄清我的问题:)

4

1 回答 1

1

唷,你在这个地方到处都是,大声笑..所以所有导入语句都在package......除了你有import flash.event.MouseEvent两次之外。它不应该存在于构造函数代码中。其次,你的事件监听器应该是这样的:

btn_terug.addEventListener(MouseEvent.CLICK, terug);

不是 btn_terug.addEventListener(MouseEvent.CLICK.terug);

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class video01 extends MovieClip
    {
        public function video01()
        {
            trace("movieclip 1 geladen");
            btn_terug.addEventListener(MouseEvent.CLICK, terug);
        }

        public function terug(evt:MouseEvent):void
        {
            trace("knop ingedrukt");
        }
    }
}

看看现在的代码有多漂亮?=)

于 2012-12-12T19:58:47.593 回答