您好我有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个按钮,用于打开带有视频的动画片段,以及用于返回主页面的按钮。 每个movieclip都有一个名为video01,video02等的类(如上所示)主要的.fla它的类名为'main'。
主页上的按钮工作,并且所有按钮都打开不同的动画片段(里面有按钮)。我想要做的是让btn_terug移除孩子。但我在第3行收到错误1046。
希望这澄清了我的问题:)
答案 0 :(得分:1)
Phew,你在这个地方到处都是,大声笑......所有导入语句都在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");
}
}
}
看看现在的代码有多漂亮? =)