Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error #1009 when switching scene or frame.

New Here ,
Jan 30, 2014 Jan 30, 2014

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.

TOPICS
ActionScript
605
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 30, 2014 Jan 30, 2014

it seems that your map doesn´t exist in any scene/frame that wants to execute

limit(map);

if you for example have limit(map) on frame 24 of your Scene 1, but the MovieClip map only "lives" on frames 1-23

you will get an error

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2014 Jan 30, 2014

any advice how to fix it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2014 Jan 30, 2014
LATEST

One way would be to remove the event listener that calls the moving function whenever you leave the frames where map exists...

stage.removeEventListener(Event.ENTER_FRAME, moving);

Another option would be to test for the existence of map in the moving function before you execute any code that targets it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines