Skip to main content
April 26, 2008
Answered

Updating Game Score: getting Type Error 1009

  • April 26, 2008
  • 4 replies
  • 556 views
Hi all,

I have a simple puzzle game which has a score keeping mechanism. When you choose to view a "clue", your score is meant to be lowered. My game is set up with the main .fla file and an external actionscript 3.0 file.

Problem is, when I try to call the function to display the new score after changing it, I get this error:
"TypeError: Error #1009: Cannot access a property or method of a null object reference."

It doesn't have a problem actually adding to the score variable, because my trace came out just fine.

I have no idea why it is doing this... Below is the code of the 2 files. Hopefully someone will be able to help!

NOTE: The part of the code my .fla file is calling is toward the very bottom of the .AS file. I just included the beginning so people could see how I had the variables for the scoring defined.
------------------
File 1: .FLA File'
(segment from inside of a movie clip called "azrie")





This topic has been closed for replies.
Correct answer
Okay, I seem to have found a work-around at least for the problem I was having.

For my Event.ADDED_TO_STAGE function onAdded, I had another call to a function out on the main timeline. This function in turn calls back the consturctor function and passes it a boolean value. True flags the if statement in the constructor that deals with outputting my score back onto the stage.

It seems like my constructor function was the only one in my class that had stage access, so this was the easier path for me to take. Although I don't like having to recall this function since it is defeating the purpose of a constructor... oh well.

Weird this is I have a movie clip which's class identifier is the name of my SlidingPuzzle class. The only way I had stage access was to call the constructor function from INSIDE this movie clip. (which is what eventually solved my problem.

For others who might be stuck in a similar spot, I'll show some of the code I used below:

4 replies

kglad
Community Expert
Community Expert
April 26, 2008
i don't see why you're loosing scope in those two functions. they are in your startSlidingPuzzle class file, correct?
April 26, 2008
Yes, I have them placed right under the constructor function :/
Correct answer
April 26, 2008
Okay, I seem to have found a work-around at least for the problem I was having.

For my Event.ADDED_TO_STAGE function onAdded, I had another call to a function out on the main timeline. This function in turn calls back the consturctor function and passes it a boolean value. True flags the if statement in the constructor that deals with outputting my score back onto the stage.

It seems like my constructor function was the only one in my class that had stage access, so this was the easier path for me to take. Although I don't like having to recall this function since it is defeating the purpose of a constructor... oh well.

Weird this is I have a movie clip which's class identifier is the name of my SlidingPuzzle class. The only way I had stage access was to call the constructor function from INSIDE this movie clip. (which is what eventually solved my problem.

For others who might be stuck in a similar spot, I'll show some of the code I used below:

kglad
Community Expert
Community Expert
April 26, 2008
that doesn't make sense. use trace(stage) in your SlidingPuzzle class to make sure it has access to your stage. if you see something like object-stage, your class has stage access and answering the next question is reasonable:

does calling showGameScore() result in your error?
April 26, 2008
when I placed the trace(stage) inside startSlidingPuzzle function, it returned back with [object Stage], however, when I placed it into the function of the class which is called to update the score it returns with "null".

Yes, calling showGameScore, and updatelead() is what is causing my error. So somehow I lost access to my stage at this point.. need to figure out how to get it back?
kglad
Community Expert
Community Expert
April 26, 2008
is startSlidingPuzzle your document class? if not, is anything created in startSlidingPuzzle appearing on stage?
April 26, 2008
startSlidingPuzzle is the constructor for the SlidingPuzzle class. As for document class... I'm not sure about that. I just have it in the same directory as my fla and it loads the .AS automatically. I tried to set it up as a document class once but it kept saying to "use a unique name not associated with any symbols in the library" (even though none of my symbols are named that).

startSlidingPuzzle creates the scoring and timer objects and places them on the stage with addChild. So yes, they are on the stage already, I am just trying to reference them later on to change the values.
April 26, 2008
Can anyone help me with this...?

I'm pretty sure the problem is arising because the dynamic text field I created via actionscript is on the stage, and I read somewhere that you can't reference display objects with a non-display object class.

Can someone tell me how I can reference my text box in order to change the text? If you're going to say about the root and stage variable please explain it first... I looked that up and tried it but it just said there was a namespace conflict.

Thanks anyone who can give me some aid!