Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-09-2012, 07:58 PM   #1
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default 1009 Error, for no noticeable reason

I am a complete rookie when it comes to flash, but I have coded in many programming languages before this.

The reason why I am so totally confused as to why this error is occurring, is simply because I didn't change any code to get this error. I was messing around with a glow filter, I test my game and BOOM. The infamous 1009 error apears when I test my little game. =[

I even pressed Ctrl + Z a million times to get back to a state where I knew my project worked, but I still get the same error.

I get an output error of: "TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DocumentMain/enterFrameHandler()"

Can anyone think of any quick fixes?

Thank you very much for any help. =]

Here's my code - pastebin(D O T)com(S L A S H)DfN3h8ye

Last edited by NylePudding; 02-09-2012 at 08:01 PM.
NylePudding is offline   Reply With Quote
Old 02-09-2012, 08:32 PM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,184
Default

I sounds like you have some reference to the object in the enterFrameHandler() function that doesn't exist. Maybe you could just comment everything in enterFrameHandler() function out and then trace them one after one to find which object isn't there and then just make sure you don't try to use object that doesn't exist.

EDIT: oh ok, I looked your code and it seems you need to instantiate the _ball before setting enterframe listener.

Last edited by -:)lauri; 02-09-2012 at 08:41 PM.
-:)lauri is offline   Reply With Quote
Old 02-10-2012, 09:09 AM   #3
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default

Okay, it sounds like the fix isn't going to be very tricky to do. But how would I instantiate the _ball exactly?

Please bare with me, like I said I'm prety new to Action Script. x]
NylePudding is offline   Reply With Quote
Old 02-10-2012, 09:17 AM   #4
SanderSoulwax
Senior Member
 
Join Date: Sep 2010
Posts: 131
Default

ActionScript Code:
_ball = new Ball();
in DocumentMain();

Done.
SanderSoulwax is offline   Reply With Quote
Old 02-10-2012, 09:38 AM   #5
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default

Haha, excellent, I looked up how to instantiate something, but I wasn't too sure how to go about it. I'm currently sitting in college, so I'll get back to you when I give it a try.

If it does work, I have no idea how my game managed to work before that. :s
NylePudding is offline   Reply With Quote
Old 02-10-2012, 08:20 PM   #6
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default

I just put "_ball = new Ball();" in DocumentMain() and I still get the same error message. Can either of you think of any other fixes?
NylePudding is offline   Reply With Quote
Old 02-11-2012, 06:59 AM   #7
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,184
Default

ActionScript Code:
public function DocumentMain():void                 {                         _vx = 0;                         _vy = 0;                        _ball = new Ball();                        // add ball to the stage                        addChild(_ball);                         _ball.buttonMode = true;                                                 addEventListener(Event.ENTER_FRAME, enterFrameHandler);                         addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);                   }

still it seems you'll get same error message from function checkBoundaryCollision() because the TextFields you're using aren't instantiated or added to the stage either.

Last edited by -:)lauri; 02-11-2012 at 07:02 AM.
-:)lauri is offline   Reply With Quote
Old 02-11-2012, 08:13 AM   #8
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default

Quote:
Originally Posted by -:)lauri View Post
I sounds like you have some reference to the object in the enterFrameHandler() function that doesn't exist. Maybe you could just comment everything in enterFrameHandler() function out and then trace them one after one to find which object isn't there and then just make sure you don't try to use object that doesn't exist.

EDIT: oh ok, I looked your code and it seems you need to instantiate the _ball before setting enterframe listener.
Here is my new DocumentMain code, and still no prevail. Same error message. =[

Code:
public function DocumentMain():void
		{
			_vx = 0;
			_vy = 0;
			
			_ball = new Ball();
			_highscore = new TextField();
			_bounces = new TextField();
			_ClickMe = new TextField();
			
			addChild(_ball);
			addChild(_highscore);
			addChild(_bounces);
			addChild(_ClickMe);

			_ball.buttonMode = true;
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			

		}
NylePudding is offline   Reply With Quote
Old 02-11-2012, 01:04 PM   #9
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

Code works fine if the objects actually exist.
BTW, you need a Ball class in order for Ball to exist.
ActionScript Code:
package {     import flash.display.MovieClip;     import flash.text.TextField;     import flash.events.Event;     import flash.events.MouseEvent;     public class Index extends MovieClip     {         public var GRAVITY:Number = 1.75;         public const BOUNCE_FACTOR:Number = 0.8;         public const DIFFICULTY_MULTIPLIER = 0.001;         public var HIT_FORCE:Number = 20;         public var _bounces:TextField;         public var _highscore:TextField;         public var _clickme:TextField;         public var _ball:Ball;         private var _vx:Number;         private var _vy:Number;         public function Index():void         {             _vx = 0;             _vy = 0;             _highscore = new TextField();             _bounces = new TextField();             _clickme = new TextField();             _ball = new Ball();             _ball.buttonMode = true;             addChild(_ball);             addChild(_bounces);             addChild(_highscore);             addChild(_clickme);             addEventListener(Event.ENTER_FRAME, enterFrameHandler);             addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);         }         private function enterFrameHandler(e:Event):void         {             //Gravitate             _vy +=  GRAVITY;             //move the ball             _ball.x +=  _vx;             _ball.y +=  _vy;             //check collisions             checkBoundaryCollision();         }         private function mouseDownHandler(e:Event):void         {             // hit the balll if it has been clicked             if (e.target == _ball)             {                 if (Number(_bounces.text) > 0)                 {                     HIT_FORCE +=  Number(_bounces.text) * DIFFICULTY_MULTIPLIER;                     GRAVITY +=  Number(_bounces.text) * DIFFICULTY_MULTIPLIER;                 }                 else                 {                     HIT_FORCE = 17;                     GRAVITY = 2;                 }                 hit(e.target.mouseX, e.target.mouseY);             }         }         private function checkBoundaryCollision():void         {             var left:Number;             var right:Number;             var top:Number;             var bottom:Number;             left = _ball.x - (_ball.width / 2);             right = _ball.x + (_ball.width / 2);             bottom = _ball.y + (_ball.height / 2);             top = _ball.y - (_ball.height / 2);             if (left < 0 && _vx < 0)             {                 _ball.x = _ball.width / 2;                 _vx *=  -1;             }             else if (right > stage.stageWidth && _vx > 0)             {                 _ball.x = stage.stageWidth - _ball.width / 2;                 _vx *=  -1;             }             if (top < 0 && _vy < 0)             {                 _ball.y = _ball.height / 2;                 _vy *=  -1;             }             else if (bottom > stage.stageHeight  && _vy > 0)             {                 _ball.y = stage.stageHeight - (_ball.height / 2);                 _vy *=   -  BOUNCE_FACTOR;                 _vx *=  BOUNCE_FACTOR;                 if (Number(_bounces.text) > Number(_highscore.text))                 {                     _highscore.text = _bounces.text;                 }                 _bounces.text = "0";             }         }         private function hit(hitX:Number, hitY:Number):void         {             // incremnt bounces             _bounces.text = String(Number(_bounces.text) + 1);             _clickme.visible = false;             //adjust vertical V             if (_vy > 0)             {                 _vy *=  -BOUNCE_FACTOR / 2;             }             _vy -= HIT_FORCE;             //adjust horizontal V             if (_vx * hitX > 0)             {                 _vx *=   -  BOUNCE_FACTOR;             }             _vx -= (hitX / _ball.width) * HIT_FORCE;         }     } }

Last edited by [afz]snickelfitz; 02-11-2012 at 01:13 PM.
[afz]snickelfitz is offline   Reply With Quote
Old 02-11-2012, 08:21 PM   #10
NylePudding
Registered User
 
Join Date: Feb 2012
Posts: 6
Default

Sorry but how would I go about making a script for the Ball? I'm just so confused, this game worked fine with my original code not so long ago. :s

EDIT - Sorry guys but I managed to fix my problem. It's really stupid actually, I totally forgot but I added a scene which had nothing on it. Deleting it fixed the problem instantly.

Thank you very much for all your help anyway. If I do get this error message again I'll know what to do. =]

Last edited by NylePudding; 02-11-2012 at 08:32 PM.
NylePudding is offline   Reply With Quote
Reply


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


All times are GMT. The time now is 06:40 AM.

///
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.