Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-07-2011, 09:39 AM   #1
HateThat
Registered User
 
Join Date: Oct 2011
Posts: 3
Exclamation Error #1009: Cannot access a property or method of a null object reference.

I've seen this on many pages and possible fixes. But I've been looking at this for days and am learning flash by myself and need some help as others dont seem to have this exact problem. Everything works fine in my code until i click on my button that calls a method from another class.

Code:
package  
{
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	public class Hardware extends MovieClip 
	
	{
		protected var originalPosition:Point;

		public function Hardware()
		{
			originalPosition = new Point(x, y);
			
			buttonMode = true;
			addEventListener(MouseEvent.MOUSE_DOWN, down);
			mouseChildren = false;
		}
		
		protected function down(event:MouseEvent): void
		{
			parent.addChild(this);
			startDrag();
			stage.addEventListener(MouseEvent.MOUSE_UP, stageUp);
		}
		
		protected function stageUp(event:MouseEvent): void
		{
			stage.removeEventListener(MouseEvent.MOUSE_UP, stageUp);
			stopDrag();
			
			if(dropTarget)
			{
				if(dropTarget.parent.name == "bl2")
				{
					
					goToHardPosition();
					
					
				}
				
				else if(dropTarget.parent.name == "bl1")
				{
					
					goToSoftPosition();
					
					
				}
				else
				{
					returnToOriginalPosition();
				}
	
			}else{
				returnToOriginalPosition();
			}
		}
		function correct()
		{
			if(dropTarget.parent.name == "bl2")
			{
				trace("true");
			}
			else if(dropTarget.parent.name == "bl1")
			{
				trace("false");
			}
			else
			{
				trace("please drag your answers over first");
			}
		}
		
		protected function goToHardPosition():void
		{
			x = 80.8;
			y = 304.8;
			buttonMode = false;
			removeEventListener(MouseEvent.MOUSE_DOWN, down);
		}
		
		protected function goToSoftPosition():void
		{
			x = 80.75;
			y = 226.8;
			buttonMode = false;
			removeEventListener(MouseEvent.MOUSE_DOWN, down);
		}
		
		protected function returnToOriginalPosition():void
		{
			x = originalPosition.x;
			y = originalPosition.y;
		}
		
		

	}
}
This is a class where i drag a button onto a blank space. If it is on the right space it was meant to just send back a trace. The "correct" method works if i call it from this class, but its the method that gives the error when i call it from the following class.


Code:
package 
{
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	
	public class Submit extends MovieClip 
	{
		
		var hardware:Hardware = new Hardware();
		
		public function Submit() 
		{
			
			
			buttonMode = true;
			mouseChildren = false;
			addEventListener(MouseEvent.CLICK, correct);
		}
		
		function correct(event:MouseEvent):void
		{
			hardware.correct();
		}
		
		
	}
	
}
This class calls the "correct" method from the hardware class. Its so it will check if the button gets drags to the right place or not. It compiles ok but when i click on the submit button to check if ive dragged to the right place, it generates ths error stated in the subject title of this thread.

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

I have obviously missed something or am screwing up the inheritance somehow. I would appreciate any help on the matter guys I'm really stuck and my mind has turned to mush!

Thanks in advance.
HateThat is offline   Reply With Quote
Old 10-07-2011, 01:34 PM   #2
HateThat
Registered User
 
Join Date: Oct 2011
Posts: 3
Default

Lol 18 views and no solutions? I didn't think this issue was that complicated :s
HateThat 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 01:41 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.