Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
Old 02-04-2008, 03:28 PM   #1
Join Date: Jan 2008
Posts: 51
Default Error #1009: Cannot access a property or method of a null...

Yep, I've found this is an infamous error msg and I've actually fixed it the first time it appeared. However, I'm not sure how to deal with it with the new field it's complaining about.

Forgive me, this is my first actionscript where I'm using a main file and its' companion package file. My very first actionscript, well I had all my code in one file and then noticed example code in tutorials were separated in packages. So, I have split off my one file into the convention where the class is in an external file but now, I am encountering the 1009 type error.

In short, I'm trying to add a sprite using an external jpg file and also added in a function so that I can move it. I put all loads and move function in the class package file. The error is that when I try to access the "addEventListener" statement, I encounter the error listed in the title. The error message (complete) is:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at asdata::Bumper()
at bumper_fla::MainTimeline/frame1()

The main file code is:

import asdata.Bumper;
var myBumper:Bumper = new Bumper();

The class package file is:

ActionScript Code:
package asdata{ import flash.display.*; import flash.net.URLRequest; import flash.events.*;   public class Bumper extends Sprite{   private var bumper:Sprite = new Sprite(); private var loader:Loader = new Loader(); private var rq:URLRequest = new URLRequest("bumper.png");   public function Bumper() { trace("entered new bumper creation");   loader.load(rq); this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBumper); //next statement is where the error occurs. //I think it's having a problem accessing stage because //it is null but I don't know what to do to fix this. stage.addEventListener(MouseEvent.MOUSE_MOVE,moveBumper); }     function loadBumper(event:Event):void { var bumperImage:BitmapData = new BitmapData(loader.width,loader.height,false,0x000000); bumperImage.draw(this.loader);   this.bumper.graphics.beginBitmapFill(bumperImage, null, true); bumper.graphics.drawRect(0,0,100,10); bumper.graphics.endFill(); bumper.x = 10; bumper.y = 290; addChild(bumper); }     function moveBumper(e:MouseEvent):void { bumper.x = e.stageX - bumper.width; } } }

How do I substantiate stage before accessing it? Or am I analyzing this error incorrectly? Also, when I had the code all in one file, a picture actually appeared when it executed the 'addChild' statement. However, now that I've separted the code into 2 files (main with .as file), nothing appears after the addChild is executed. :x Am I wrong to assume that anything added to the display list in a class will not appear? What am I doing wrong here, too?

Any help is appreciated,
Marion the Mighty Confused

P.S. I'm sorry the program isn't indented correctly, the editor stripped out my tabs and extra spaces.

Last edited by dr_zeus; 02-04-2008 at 05:34 PM. Reason: added [as][/as] formatting tags
MarionC is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access property within a tabnavigator pane? DrGoomba ActionScript 3.0 1 02-06-2007 04:38 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
Service threw an exception during method invocation: null Dawnthea Flash Remoting 2 09-01-2004 01:37 PM
inheritance - Mortimer Jazz ActionScript 1.0 (and below) 10 07-24-2003 09:51 PM
Random fades rabblerouser ActionScript 1.0 (and below) 2 05-05-2003 03:20 PM

All times are GMT. The time now is 07:14 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.