Copy link to clipboard
Copied
Hi,
I'm making a Flash game and rather than putting all the AS3 on a seperate .as file, I'm throwing it on the timeline, which may or may not be a mistake since this game is getting really big, really fast and messy.
And so I'm getting this error when I test:
TypeError: Error #1009: Cannot access a property or method of a null object reference at GameBeta_MainTimeline_fla::MainTimeline/frame1()
From what I've read on this error, it refers to something that isn't instantiated yet, like something that's out of order? Like I'm referring to something that doesn't exist at the point in time that I'm referring to it? So I'm looking at my AS3 and have NO idea. Here is what I have written:
stop();
//TITLE PAGE
play_game.addEventListener(MouseEvent.CLICK, startgame)
function startgame(evt:MouseEvent):void
{
gotoAndStop("Name Input");
}
//Name and Gender input page
var userName:String;
inputField.addEventListener(Event.CHANGE, onInput)
function onInput(e:Event):void
{
outputField.text = "So your name is " + inputField.text + " are you sure?";
userName = inputField.text;
}
confirm_input.addEventListener(MouseEvent.CLICK, toCreationpg)
function toCreationpg(evt:MouseEvent):void
{
gotoAndStop("Fem Creation");
outputField.text = "So your name is "+ userName;
}
//Character Creation Page
readytostart.addEventListener(MouseEvent.CLICK, firstscene_plz)
function firstscene_plz(evt:MouseEvent):void
{
gotoAndStop("Day03");
outputField.text = "Let's make your character, "+ userName;
}
So, any ideas as to why I'm getting this error?
Before I had each page with it's own Actionscript and buttons inside their own movieclips on the timeline. That was getting confusing so I took everything out of the movieclips to place everything on one timeline and have one layer of Actionscript hoping to simplify things and find the problem easier. No luck. It's supposed to have a Title page and a button that goes to the 2nd page where you input your name, and while you type, it shows your name before you confirm by hitting another button that finally goes to the Character Creation page. When I test, I just get that Error#1009, it'll get to the 2nd page for the name input, but the text fields act wacky and the button to proceed isn't working. I'm hoping that when I find the source of this error, the rest will be fixed as well.
Thanks in advance for any advice offered! I'll greatly appreciate it.
there are many ways to create that error that are undetectable from inspecting your fla unless you backtrack the steps you took to create it. and that's hardly worthwhile.
and there's only one way to ensure you won't see that error: put inputField in its own layer and make sure that there's only one keyframe in that layer. test. you should see no problem if you assign that instance name in that keyframe (unless you have another inputField somewhere).
from there you can start adding keyframes a
...Copy link to clipboard
Copied
click file/publish settings/flash and tick "permit debugging". retest. the line number with the null object will be in the error message. if that doesn't allow you to fix the problem quickly, copy and paste that line of code.
Copy link to clipboard
Copied
Ah, I've checked off the Debugging option! Thanks for that tip by the way. It definitely helps. And it says it's this line:
inputField.addEventListener(Event.CHANGE, onInput)
I don't know what's wrong with it.
Copy link to clipboard
Copied
inputField doesn't exist when that code executes.
Copy link to clipboard
Copied
Yeah, that's what makes me even more confused. I have a seperate file where I'm testing the name input mechanics alone, just using this piece of actionscript, one input box with an instance inputField and a dynamic box outputField, a button, instance enter_name, that confirms and repeats the input on the next page. And it works.
inputField.addEventListener(Event.CHANGE, onInput)
var userName:String;
function onInput(e:Event):void
{
outputField.text = "You typed " + inputField.text;
userName = inputField.text;
}
enter_name.addEventListener(MouseEvent.CLICK, onClick)
function onClick(evt:MouseEvent):void
{
gotoAndStop("frame two");
outputField.text = "So your name is "+ userName;
}
So I don't get the error with that seperate file so could it be that other things are conflicting with this? Perhaps the order in which I've written my actionscript or the way I've organized my frames? In my other file, it says it's the inputField Event Listener but it'll work when I take out all the other frames and script...
Copy link to clipboard
Copied
there are many ways to create that error that are undetectable from inspecting your fla unless you backtrack the steps you took to create it. and that's hardly worthwhile.
and there's only one way to ensure you won't see that error: put inputField in its own layer and make sure that there's only one keyframe in that layer. test. you should see no problem if you assign that instance name in that keyframe (unless you have another inputField somewhere).
from there you can start adding keyframes and as long as you don't remove inputField from any keyframes your code will continue to work.
Copy link to clipboard
Copied
AH it worked! I put that piece of script in it's own keyframe like you suggested because what happened was, I commented out that piece at first to see if I still got the error, and I DID but it chose the next event listener instead. So I realized it wasn't that particular line but maybe Flash was just getting confused from having all my script in one keyframe and I wasn't using packages or classes or anything to really seperate. So, I just put each event listener & relating functions in their own keyframes lined up with their pertaining buttons/scenes/whatever, and it works. I only plan to have that one input box so it should be fine. Thanks so much!
Copy link to clipboard
Copied
you're welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more