Skip to main content
Participating Frequently
January 15, 2014
Answered

TypeError: Error #1009: Cannot access a property or method of a null object reference

  • January 15, 2014
  • 1 reply
  • 342 views

For some reason when ever I add the Mouse event listener I get the #1009 error and some stuff dissapears and the clicking function wont work, can anyone help?

package

{

          import flash.display.*;

          import flash.text.*;

          import flash.events.MouseEvent;

          import flash.events.KeyboardEvent;

          import flash.ui.*;

          import flash.utils.*;

          import flash.geom.*;

          import flash.net.*;

          import flash.media.Sound;

          import flash.media.SoundTransform;

          import flash.media.SoundChannel;

          import flash.net.URLRequest;

          import flash.display.Bitmap;

          import flash.display.Sprite;

          import flash.events.Event;

          import flash.utils.Timer;

          import flash.events.TimerEvent;

          public class Platforms extends Sprite

          {

                    var Floor = new floor();

                    var HighLightBox=new highLightBox();

                    var nyEditor:int = 0;

                    var nxEditor:int = 0;

                    var ExFloor=new exFloor();

                    var tFloor:exFloor = new exFloor  ;

                    var bEditorClick:Boolean = false;

                    var arFloor = new Array();

                    var tmrBoxes:Timer = new Timer(35);

                    public function Platforms()

                    {

                              addChild(ExFloor);

                              addChild(Floor);

                              Floor.y = 500;

                              Floor.x = 300;

                              // constructor code

                             stage.addEventListener(MouseEvent.CLICK,Clicking);

                              tmrBoxes.addEventListener("timer",timerBoxes);

                              tmrBoxes.start();

                    }

                    public function TouchingGround(HeroGroundTouch:Sprite):Boolean

                    {

                              if (HeroGroundTouch.hitTestObject(Floor))

                              {

                                        return true;

                              }

                              return false;

                    }

                    public function Clicking(e:MouseEvent):void

                    {

                              if (bEditorClick==false)

                              {

                                        nxEditor = mouseX;

                                        nyEditor = mouseY;

                                        addChild(HighLightBox);

                                        HighLightBox.x = mouseX;

                                        HighLightBox.y = mouseY;

                                        bEditorClick = true;

                              }

                              else

                              {

                                        trace("            PlaceFloor("+nxEditor+","+nyEditor+","+(mouseX-nxEditor)+","+(mouseY-nyEditor)+");");

                                        PlaceFloor(nxEditor,nyEditor,(mouseX-nxEditor),(mouseY-nyEditor));

                                        removeChild(HighLightBox);

                                        bEditorClick = false;

                              }

                    }

                    public function PlaceFloor(nx:int,ny:int,nWidth:int,nHeight:int):void

                    {

                              tFloor=new exFloor();

                              addChild(tFloor);

                              arFloor.push(tFloor);

                              tFloor.x = nx;

                              tFloor.y = ny;

                              tFloor.width = nWidth;

                              tFloor.height = nHeight;

                    }

                    function timerBoxes(eventArgs:TimerEvent)

                    {

                              HighLightBox.width = mouseX - HighLightBox.x;

                              HighLightBox.height = mouseY - HighLightBox.y;

                    }

          }

}

This topic has been closed for replies.
Correct answer Ned Murphy

The stage may not yet exist for that object by the time you are trying to target it.  Use an ADDED_TO_STAGE event listener for that happening and use the event handler for it to deal with adding the listener to the stage.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 15, 2014

The stage may not yet exist for that object by the time you are trying to target it.  Use an ADDED_TO_STAGE event listener for that happening and use the event handler for it to deal with adding the listener to the stage.