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

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

New Here ,
Jan 15, 2014 Jan 15, 2014

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;

                    }

          }

}

TOPICS
ActionScript
322
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

correct answers 1 Correct answer

LEGEND , Jan 15, 2014 Jan 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.

Translate
LEGEND ,
Jan 15, 2014 Jan 15, 2014
LATEST

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.

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