Error #1009 when switching scene or frame.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at map_fla::MainTimeline/limit()
at map_fla::MainTimeline/moving()
here is my code
backS1.addEventListener(MouseEvent.MOUSE_DOWN, goS1);
function goS1(Event😞void{
gotoAndStop(1, "Scene 1");
}
F5.addEventListener(MouseEvent.MOUSE_DOWN, gotoF5);
function gotoF5(Event😞void{
gotoAndStop(5);
}
var toR:Boolean=false;
var toL:Boolean=false;
var toU:Boolean=false;
var toD:Boolean=false;
stage.addEventListener(KeyboardEvent.KEY_UP, notClick);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onClick);
stage.addEventListener(Event.ENTER_FRAME, moving);
function onClick(event:KeyboardEvent😞void {
switch (event.keyCode) {
case Keyboard.RIGHT :
toR=true;
break;
case Keyboard.LEFT :
toL=true;
break;
case Keyboard.UP :
toU=true;
break;
case Keyboard.DOWN :
toD=true;
break;
}
}
function notClick(event:KeyboardEvent😞void {
switch (event.keyCode) {
case Keyboard.RIGHT :
toR=false;
break;
case Keyboard.LEFT :
toL=false;
break;
case Keyboard.UP :
toU=false;
break;
case Keyboard.DOWN :
toD=false;
break;
}
}
function moving(event:Event😞void {
limit(map);
if (toR) {
map.x-=5;
}
if (toL) {
map.x+=5;
}
if (toU) {
map.y+=5;
}
if (toD) {
map.y-=5;
}
}
navU.addEventListener(MouseEvent.MOUSE_DOWN, goU);
navD.addEventListener(MouseEvent.MOUSE_DOWN, goD);
navR.addEventListener(MouseEvent.MOUSE_DOWN, goR);
navL.addEventListener(MouseEvent.MOUSE_DOWN, goL);
navC.addEventListener(MouseEvent.MOUSE_DOWN, goC);
function goU(Event😞void{
map.y += 25;
}
function goD(Event😞void{
map.y -= 25;
}
function goR(Event😞void{
map.x -= 25;
}
function goL(Event😞void{
map.x += 25;
}
function goC(Event😞void{
map.x = stage.stageWidth/2;
map.y = stage.stageHeight/2;
}
map.addEventListener(MouseEvent.MOUSE_DOWN, Drag);
map.addEventListener(MouseEvent.MOUSE_UP, Drop);
map.addEventListener(MouseEvent.MOUSE_OUT, Drop);
function Drag(Event😞void {
map.startDrag();
}
function Drop(Event😞void {
map.stopDrag();
}
function limit(o:MovieClip) {
if (o.x + 364.5 < 500) {
o.x = 500 - 364.5;
}
else
if (o.x - 364.5 > 50) {
o.x = 50 + 364.5;
}
if (o.y + 309.5 < 375) {
o.y = 375 - 309.5;
}
else
if (o.y - 309.5 > 25) {
o.y = 25 + 309.5;
}
}
when I run my code, it's going well. the problem when I switch to another scene or frame it shows error #1009 and become lagging. but the code can still running. I dont know where the problem is. I'm totally noob. ty in advance.
