A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Can somone help me debug a -1009 error please.

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    82

    Question Can somone help me debug a -1009 error please.

    My error looks like this :

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at QuizApp/createButtons()
    at QuizApp()

    My QuizApp is an Actionscript file that runs with another for my quiz.
    The createButtons() is accessed like this

    package{
    public class QuizApp extends Sprite {
    public function QuizApp() {
    createQuestions();

    It runs by itself fine but when i attatch it to play off a button i get this error, i would really appreciate some advice on how to go about figuring this out.
    Thanks

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Can you post more than 4 lines of code? Post the createButtons and createQuestions functions as well as the usage you are trying.

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    82
    Yea sure and thanks for the reply.

    My QuizApp is an Actionscript file with some of the below and its loaded as a document class into a blank 3.0 flash file called Quiz.fla with the buttons in the library. The only problem is, this error occures when i load the Quiz.fla from a button on another timeline, otherwise it works fine.

    Code:
    package {  
    	import flash.display.Sprite;  
    	import fl.controls.Button;  
    	import flash.events.MouseEvent;   
    	import flash.text.TextField;  
    	import flash.text.TextFieldAutoSize;   
    	public class QuizApp extends Sprite {   
    		//for managing questions:     
    		private var quizQuestions:Array;      
    		private var currentQuestion:QuizQuestion;    
    		private var currentIndex:int = 0;    
    		//the buttons:            
    		private var nextButton:Button;     
    		private var finishButton:Button;     
    		//scoring and messages:    
    		private var score:int = 0;      
    		private var status:TextField;       
    		public function QuizApp() {      
    			quizQuestions = new Array();         
    			createQuestions();          
    			createButtons();          
    			createStatusBox();          
    			addAllQuestions();          
    			hideAllQuestions();        
    			firstQuestion();      
    		}
    I have my questions then the button appear from this:

    Code:
    private function createButtons() {        
    	var yPosition:Number = stage.stageHeight - 40;             
    	nextButton = new Button();    
    	nextButton.label = "Next";       
    	nextButton.x =30;   
    	nextButton.y = yPosition;        
    	nextButton.addEventListener(MouseEvent.CLICK, nextHandler);     
    	addChild(nextButton);          
    	finishButton = new Button();         
    	finishButton.label = "Finish";       
    	finishButton.x = nextButton.x + nextButton.width + 40;   
    	finishButton.y = yPosition;     
    	finishButton.addEventListener(MouseEvent.CLICK, finishHandler);  
    	addChild(finishButton);

  4. #4
    Member
    Join Date
    Mar 2009
    Posts
    82
    I debugged it and it shows the problem lies on 2 lines



    The first is when

    Code:
    public function QuizApp() {
    calls upon

    Code:
    createButtons();


    The second is when

    Code:
    private function createButtons() {
    calls upon

    Code:
    var yPosition:Number = stage.stageHeight - 40;

  5. #5

  6. #6
    Member
    Join Date
    Mar 2009
    Posts
    82
    yes another FLA. My timelines, i have a main menu.fla which has a button that loads the intro.fla, that is frame based cuz when its finished (on frame w.e) it loads the Quiz.fla im just not sure where to insert your line

  7. #7
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Do you have any items in the library that are non-existing in one of your FLA files?

    Can you zip them up and post them?

  8. #8
    Member
    Join Date
    Mar 2009
    Posts
    82
    um, the intro.fla which calls the Quiz.fla to play when finished has custom buttons but the Quiz.fla library only has a button and a radio button which were pulled out of the common library for use by its document class QuizApp which is an actionscript file. The Quiz.fla also has another actionscript file attached to it call QuizQuestions. Im not sure if that helps at all.
    but thanks so much for the reply, i really appreciate it.
    I dont know what you mean by zip them up and post them though.

  9. #9
    Junior Member
    Join Date
    Feb 2009
    Location
    San Francisco
    Posts
    6
    I'm pretty sure it is because CreateButtons can't find the stage instance. I've had trouble with this in the past. This would affect the first line of the function.

    I ususally get round this by manually adding a sprite to the stage in the main fla file. Have it match the stage dimensions and be accessible by action script. Give it a variable name in the IDE, eg myStage.

    If this is all running in your document class, the function should work if you change all the references of 'stage' to 'myStage'. If it's not in the document class you will have to pass a reference to myStage into the constructor of your other classes.

    I hope this helps.

    P.S. This is actually a good practice to get into as if you are ever wrapping your swf in another, eg for widget sharing or something, you may find that calls to stage are blocked by the containing movie.
    Last edited by peter.hastie; 04-16-2009 at 05:11 PM. Reason: Thought of more stuff (P.S.)

  10. #10
    Member
    Join Date
    Mar 2009
    Posts
    82
    Ah i c, i get what your doing. Um would you be able to give me a quick crash course on how to add sprite to stage for us unexperienced guys out there
    thanks for the reply very much

  11. #11
    Junior Member
    Join Date
    Feb 2009
    Location
    San Francisco
    Posts
    6
    Hi CoreyC,

    Sorry I haven't posted up an example of what I was talking about yet. I shall try to do that today or tomorrow. In the meantime though, have you tried moving the call to stage to after the line where the button is added to the stage?

    PHP Code:
    addChild(nextButton);
    nextButton.stage.stageHeight 40
    Last edited by peter.hastie; 04-20-2009 at 05:52 PM.

  12. #12
    Member
    Join Date
    Mar 2009
    Posts
    82
    Hi peter
    What do you mean by moving the call to stage to after the line where the button is added to the stage?

    Im not exactly sure what you mean by this because my buttons and my code for the QuizApp.swf are on different files, do you mean calling to this swf from the timeline that has the button instead of after?

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