我真的需要帮助,我已经被困在这个问题上了2天。导航回另一帧时,我不断收到此错误!
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at product_fla::MainTimeline/frog_mcRelease()
frog_mc继续前进到另一帧!不知道什么是错的。
感谢
我的代码:
import flash.events.Event;
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=frog_mc.x;
var orig1Y:Number=frog_mc.y;
var orig2X:Number=queen_mc.x;
var orig2Y:Number=queen_mc.y;
var orig3X:Number=apple_mc.x;
var orig3Y:Number=apple_mc.y;
stage.removeEventListener(Event.ENTER_FRAME, frog_mcRelease);
frog_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
frog_mc.addEventListener(MouseEvent.MOUSE_UP, frog_mcRelease);
queen_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
queen_mc.addEventListener(MouseEvent.MOUSE_UP, queen_mcRelease);
apple_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
apple_mc.addEventListener(MouseEvent.MOUSE_UP, apple_mcRelease);
done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
frog_mc.buttonMode=true;
queen_mc.buttonMode=true;
apple_mc.buttonMode=true;
function dragTheObject(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function frog_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_frog.hitTestPoint(item.x,item.y)) {
item.x=drop_frog.x;
item.y=drop_frog.y;
} else {
item.x=orig1X;
item.y=orig1Y;
}
};
function queen_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_queen.hitTestPoint(item.x,item.y)) {
item.x=drop_queen.x;
item.y=drop_queen.y;
} else {
item.x=orig2X;
item.y=orig2Y;
}
};
function apple_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_apple.hitTestPoint(item.x,item.y)) {
item.x=drop_apple.x;
item.y=drop_apple.y;
} else {
item.x=orig3X;
item.y=orig3Y;
}
};
function checkAnswers(event:MouseEvent):void {
if (drop_frog.hitTestPoint(frog_mc.x,frog_mc.y) &&
drop_queen.hitTestPoint(queen_mc.x,queen_mc.y) &&
drop_apple.hitTestPoint(apple_mc.x,apple_mc.y)) {
wrong_mc.visible = false;
right_mc.visible = true;
} else {
wrong_mc.visible = true;
right_mc.visible = false;
}
}
function reset(event:MouseEvent):void {
frog_mc.x=orig1X;
frog_mc.y=orig1Y;
queen_mc.x=orig2X;
queen_mc.y=orig2Y;
apple_mc.x=orig3X;
apple_mc.y=orig3Y;
right_mc.visible=false;
wrong_mc.visible=false;
}
答案 0 :(得分:1)
var item:MovieClip = MovieClip(event.target);
我认为你应该首先像这样创建一个对MovieClip的新引用
var item:MovieClip = new MovieClip();
我认为这应该解决问题