dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4

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

    I use to get this problem and be able to solve it, but i'm stumped. My button use to work and then I added some code in the proceedToGame function and I get this error. Thanks in advance

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


    Code:
    package actions {
    	
    	/*always extend a class using movieclip instead of sprite when using flash.*/
    
    	import flash.display.MovieClip;
    	import flash.events.*;
    	import flash.net.*;
    	import flash.text.*;
    	import nextButton;
    	/*create our class*/
    	
    	public class main extends MovieClip {
    		
    		var next_btn:nextButton = new nextButton;
    		
    		public function main ():void {
    					stop();
    			/*
    			buttonMode gives the submit button a rollover
    			*/
    			submit_button.buttonMode = true;
    
    			/*
    			what this says is that when our button is pressed, the checkLogin function will run
    			*/
    
    			submit_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
    			
    			/*
    			set the initial textfield values
    			*/
    			
    			username.text = "";
    			password.text = "";
    		
    		}
    
    		/*
    		the function to check login
    		*/
    		
    		public function checkLogin (e:MouseEvent):void {
    		
    			/*
    			check fields before sending request to php
    			*/
    			
    			if (username.text == "" || password.text == "") {
    				
    				/*
    				if username or password fields are empty set error messages
    				*/
    				
    				if (username.text == "") {
    				
    				username.text = "Enter your username";
    				
    				} 
    				
    				if (password.text == "") {
    				
    				password.text = "Enter your password";
    				
    				}
    			
    			} else {
    				
    				/*
    				init function to process login
    				*/
    			
    				processLogin();
    			
    			}
    		
    		}
    		
    		/*
    		function to process our login
    		*/
    		
    		public function processLogin ():void {
    			
    			/*
    			variables that we send to the php file
    			*/
    		
    			var phpVars:URLVariables = new URLVariables();
    			
    			/*
    			we create a URLRequest  variable. This gets the php file path.
    			*/
    			
    			var phpFileRequest:URLRequest = new URLRequest("php/controlpanel.php");
    			
    			/*
    			this allows us to use the post function in php
    			*/
    			
    			phpFileRequest.method = URLRequestMethod.POST;
    			
    			/*
    			attach the php variables to the URLRequest
    			*/
    			
    			phpFileRequest.data = phpVars;
    			
    			/*
    			create a new loader to load and send our urlrequest
    			*/
    			
    			var phpLoader:URLLoader = new URLLoader();
    			phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;			
    			phpLoader.addEventListener(Event.COMPLETE, showResult);
    			
    			/*
    			now lets create the variables to send to the php file
    			*/
    			
    			phpVars.systemCall = "checkLogin";
    			phpVars.username = username.text;
    			phpVars.password = password.text;
    			
    			/*
    			this will start the communication between flash and php
    			*/
    			
    			phpLoader.load(phpFileRequest);
    		
    		}
    		
    		/*
    		function to show the result of the login
    		*/
    		
    		public function showResult (event:Event):void {
    			
    			/*
    			this autosizes the text field
    			***** You will need to import flash's text classes. You can do this by: 
    			import flash.text.*;
    			*/
    			result_text.autoSize = TextFieldAutoSize.LEFT;
    			result_text.text = "Processing please wait...";
    			/*
    			this gets the output and displays it in the result text field
    			*/
    			if(event.target.data.systemResult == "Approved")
    			{	
    				addChild(next_btn);
    				result_text.text = event.target.data.systemResult;
    				next_btn.buttonMode = true;
    				// naragor@gmail.com
    				next_btn.x = 350;
    				next_btn.y = 275;
    				next_btn.addEventListener(MouseEvent.CLICK, proceedToGame);
    			}
    			else{
    				result_text.text = event.target.data.systemResult;
    			}	
    		
    		}
    		public function proceedToGame(event:Event):void
    		{
    			gotoAndStop(2);
    			removeChild(next_btn);
    			var phpVars2:URLVariables = new URLVariables();
    			var phpFileRequest2:URLRequest = new URLRequest("php/usersOnline.class.php");
    			
    			phpFileRequest2.method = URLRequestMethod.POST;
    			
    			phpFileRequest2.data = phpVars2;
    			
    			var phpLoader2:URLLoader = new URLLoader();
    			phpLoader2.dataFormat = URLLoaderDataFormat.TEXT;			
    			phpLoader2.addEventListener(Event.COMPLETE, showUsersOnline);
    			
    			phpVars2.username2 = username.text;
    			
    		
    			phpLoader2.load(phpFileRequest2);
    		}
    	
    		public function showUsersOnline(event:Event):void
    		{
    			users_online_txt.text =  event.target.data.userCount;
    		}
    	}
    
    }

  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Alright well I solved the problem, but in a way I really didn't want it to be solved.

    In the showResult function I removed the event listener and just called a function called "clickzorz". Then I just made a function called clickzorz that had the event listener and everything works fine now.

  3. #3
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    did the error come with any additional text?
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Why don't you use double line (//) comments in your code and use [HIGHLIGHТ=actionscripit][/HIGHLIGHТ]tags instead of "code"

    Your code is absolutely unreadable

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center