Skip to main content
Participating Frequently
February 1, 2013
Question

Error 1009, the movieClip Exist but it's null when Traced

  • February 1, 2013
  • 1 reply
  • 1893 views

Hi ! Im new here, and i got a really irritating problem ,

I have a MovieClip called testCam in the 2nd frame on the stage, in testCam MovieClip i have Button, Movie Clip ect. i crating a seperated map about 27 frames, and each frame have a same MovieClip, so i made a function :

function addMovement():void{

          addEventListener(Event.ENTER_FRAME, movement);

          stage.addEventListener(KeyboardEvent.KEY_DOWN, pencet);

          stage.addEventListener(KeyboardEvent.KEY_UP, angkat);

          testCam.bag1.addEventListener(MouseEvent.CLICK, goToInventory);

}

and at each frame i just called addMovement to get a same function.

so i created all the frame, with the testCam, and called addMovement(); each frame, everything was normal, until i make a button inside the testCam Movie Clip.

I have a MC named Hoe, and a MC named Tool Box, i created button with Tool Box behind the Hoe, i think i'll be normal, because no Code on both MC, but all i get is, error1009:Error #1009: Cannot access a property or method of a null object reference.

When i use Ctrl+Shift+Enter, its point to this :

    

testCam.bag1.addEventListener(MouseEvent.CLICK, goToInventory);

I was check thousand times, and testCam is exist in stage, but after i put the new button there it's got error.

I try a simple experiment, i trace the testCam is null or not, and its strange, when i delete the new button there, its said testCam is exist, but after i put that new button its said testCam is null.

Please help me , sorry for my bad english.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
February 1, 2013

Where is the code and where is the object?  Have you traced both the movieclip and the button inside it?

Ethanz92Author
Participating Frequently
February 1, 2013

Here is all the related code :

Movement :

function movement(e):void{

          testCam.placeText.text = placeStatus;

          //testCam.placeText.text = currentFrame;

          if(atas == true && testCam.y > 0 + testCam.height/2){

                    testCam.y -= 3;

                    myCursor.y -= 3;

          }

          if(bawah == true && testCam.y < 600 - testCam.height/2){

                    testCam.y += 3;

                    myCursor.y += 3;

          }

          if(kanan == true && testCam.x < 800 - testCam.width/2){

                    testCam.x += 3;

                    myCursor.x += 3;

          }

          if(kiri == true && testCam.x > 0 + testCam.width/2){

                    testCam.x -= 3;

                    myCursor.x -= 3;

          }

          if(cursorStatus == "Hoe"){

                    myCursor.cursorHoe.gotoAndStop(hoeLevel);

          }

          testCam.coinUI.moneyText.text = money;

          testCam.mineralUI.mineralText.text = mineral;

          dateSystem(testCam.hariText,testCam.tahunText,testCam.jamText);

          dayNight();

          energyCalculation();

          testCam.energyTank.energyText.text = energyPercent+"%";

          hungerCalculation();

          testCam.hungerTank.hungerText.text = hungerPercent+"%";

}

Pencet & Angkat Function :

function pencet(e:KeyboardEvent):void{

          if(e.keyCode == 87 || e.keyCode == Keyboard.UP){

                    atas = true;

          }

          if(e.keyCode == 83 || e.keyCode == Keyboard.DOWN){

                    bawah = true;

          }

          if(e.keyCode == 65 || e.keyCode == Keyboard.LEFT){

                    kiri = true;

          }

          if(e.keyCode == 68 || e.keyCode == Keyboard.RIGHT){

                    kanan = true;

          }

}

function angkat(e:KeyboardEvent):void{

          if(e.keyCode == 87 || e.keyCode == Keyboard.UP){

                    atas = false;

          }

          if(e.keyCode == 83 || e.keyCode == Keyboard.DOWN){

                    bawah = false;

          }

          if(e.keyCode == 65 || e.keyCode == Keyboard.LEFT){

                    kiri = false;

          }

          if(e.keyCode == 68 || e.keyCode == Keyboard.RIGHT){

                    kanan = false;

          }

}

goToInventory Function :

function inventoryDirect():void{

          normalCursor();

          energy += eConsume;

          tempCamX = testCam.x;

          tempCamY = testCam.y;

          assignCam = true;

          beforeWay = placeStatus;

          placeStatus = "Inventory";

          stopMovement();

          gotoAndStop(3);

}

yeah, it's error 1009 when i trace the button and it's said null when i traced the testCam, with trace(testCam == null), its come out with true.

The code and the object is in the same frame.

Ned Murphy
Legend
February 1, 2013

Does the object also exist in frame 1?  If it does, does it have the instance name assigned in frame 1?