PDA

View Full Version : TypeError: Error #1009



xvkarbear
December 16th, 2009, 03:27 PM
I don't know why this is not working.

I have a short quiz where in step one, the user clicks a button that populates text in a dynamic textbox. Then in step two, they do the exact same thing again.

I've done research that suggests I'm getting this error because something is not loaded or something is not on the stage, but all of the items are on the stage and I'm not loading anything externally. I've narrowed it down to my first set of event listeners, but they all look normal to me.

Here's the code (forgive the mess, there's probably an easier way to acheive what I'm trying to do, but I'm not versed enough to do it) and the fla:


stop();
var firstak1:String = "The conference is in Detroit";
var secondak1:String = " please let me know if you have any questions.";
var secondbk1:String = " I can easily drive to it.";
var secondck1:String = " the cost could be as low as $250 if we register by tomorrow.";
var seconddk1:String = " I think this would be a great opportunity to learn the latest techniques to help improve our business.";
var secondek1:String = " we won’t need to disrupt any of our client’s scheduled appointments.";
var pfork1:String = ", for";
var pbutk1:String = ", but";
var psok1:String = ", so";
var pandk1:String = ", and";
var pork1:String = ", or";
var psemik1:String = ";";
var pnork1:String = ", nor";
var pyetk1:String = ", yet";
var pperiodk1:String = ".";

myphrase.text = firstak1;
yesno.text = " ";
mycontinue.x = -1000;

scfor.addEventListener(MouseEvent.MOUSE_DOWN, optfork1);
scbut.addEventListener(MouseEvent.MOUSE_DOWN, optbutk1);
scso.addEventListener(MouseEvent.MOUSE_DOWN, optsok1);
scand.addEventListener(MouseEvent.MOUSE_DOWN, optandk1);
scor.addEventListener(MouseEvent.MOUSE_DOWN, optork1);
scnor.addEventListener(MouseEvent.MOUSE_DOWN, optnork1);
scyet.addEventListener(MouseEvent.MOUSE_DOWN, optyetk1);
scsemicolon.addEventListener(MouseEvent.MOUSE_DOWN , optsemicolonk1);
scperiod.addEventListener(MouseEvent.MOUSE_DOWN, optperiodk1);
mycontinue.addEventListener(MouseEvent.MOUSE_DOWN, nextscenek1);

function buttonsgooffk1(e:MouseEvent):void {
ic1.mouseEnabled = false;
ic2.mouseEnabled = false;
ic3.mouseEnabled = false;
ic4.mouseEnabled = false;
ic5.mouseEnabled = false;
scfor.mouseEnabled = false;
scbut.mouseEnabled = false;
scso.mouseEnabled = false;
scand.mouseEnabled = false;
scor.mouseEnabled = false;
scnor.mouseEnabled = false;
scyet.mouseEnabled = false;
scsemicolon.mouseEnabled = false;
scperiod.mouseEnabled = false;
}

function nextscenek1(e:MouseEvent):void{
gotoAndPlay(5);
}

function optfork1(e:MouseEvent):void {
yesno.text = "Incorrect. Try Again.";
}

function optbutk1(e:MouseEvent):void {
var phrasek1:String = firstak1 + pbutk1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}

function optsok1(e:MouseEvent):void {
var phrasek1:String = firstak1 + psok1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}

function optandk1(e:MouseEvent):void {
var phrasek1:String = firstak1 + pandk1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}

function optork1(e:MouseEvent):void {
yesno.text = "Incorrect. Try Again.";
}

function optnork1(e:MouseEvent):void {
yesno.text = "Incorrect. Try Again.";
}

function optyetk1(e:MouseEvent):void {
var phrasek1:String = firstak1 + pyetk1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}

function optsemicolonk1(e:MouseEvent):void {
var phrasek1:String = firstak1 + psemik1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}

function optperiodk1(e:MouseEvent):void {
var phrasek1:String = firstak1 + pperiodk1;
myphrase.text = phrasek1;

ic1.addEventListener(MouseEvent.MOUSE_DOWN, secondoptak1);
ic2.addEventListener(MouseEvent.MOUSE_DOWN, secondoptbk1);
ic3.addEventListener(MouseEvent.MOUSE_DOWN, secondoptck1);
ic4.addEventListener(MouseEvent.MOUSE_DOWN, secondoptdk1);
ic5.addEventListener(MouseEvent.MOUSE_DOWN, secondoptek1);


function secondoptak1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}

function secondoptbk1(e:MouseEvent):void {
myphrase.text = phrasek1 + secondbk1;
yesno.text = "Correct!";
buttonsgooffk1(null);
mycontinue.x = 500;
}

function secondoptck1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptdk1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
function secondoptek1(e:MouseEvent):void {yesno.text = "Incorrect. Try Again.";}
}http://www.mediafire.com/file/u1uncwmnmzz/eng100_independentclause2.fla (CS4)

senocular
December 16th, 2009, 04:04 PM
Obligatory see if this helps:
http://senocular.com/flash/tutorials/runtimeerrors/#1009

xvkarbear
December 16th, 2009, 04:12 PM
Obligatory see if this helps:
http://senocular.com/flash/tutorials/runtimeerrors/#1009

Yup. I did that. That's how I narrowed it down to my event listeners. It specifically points out my first one:


scfor.addEventListener(MouseEvent.MOUSE_DOWN, optfork1);

but it looks okay to me.

senocular
December 16th, 2009, 04:46 PM
if you trace scfor before that line, what do you get?

xvkarbear
December 16th, 2009, 05:00 PM
if you trace scfor before that line, what do you get?


yesno.text = " ";
mycontinue.x = -1000;

trace (scfor);

scfor.addEventListener(MouseEvent.MOUSE_DOWN, optfork1);
scbut.addEventListener(MouseEvent.MOUSE_DOWN, optbutk1);
scso.addEventListener(MouseEvent.MOUSE_DOWN, optsok1);gives me:


[object SimpleButton]

senocular
December 16th, 2009, 05:09 PM
And that was the line that the debugger told you was causing the error?

xvkarbear
December 16th, 2009, 05:13 PM
And that was the line that the debugger told you was causing the error?

Yes. If by telling me, you mean there was a golden/yellow arrow pointing to it.

I need to point out that I don't get that error when I run it. It's only after I get to the point in the animation where they press the nextscenek1 button.

senocular
December 16th, 2009, 05:16 PM
if you're going to another scene then its possible scfor will go null. Is the trace you posted the trace before the error occurred? That's the important one.

xvkarbear
December 16th, 2009, 05:35 PM
if you're going to another scene then its possible scfor will go null. Is the trace you posted the trace before the error occurred? That's the important one.

yeah the trace is before the error occurred. here's the whole thing:


[object SimpleButton]
(The following doesn't appear until I click the button)
null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at eng100_independentclause2_fla::MainTimeline/frame1()It doesn't seem to care if I'm going to the next scene or a frame within the current scene gotoAndStop(5) or gotoAndStop(1, '02'). The same error occurs.

senocular
December 16th, 2009, 06:33 PM
yeah, because it's null - see the null trace? That's the error. You're running that code when scfor is null. You either need to not run it, keep scfor from going null (removed from timeline?) or figure out whatever other logic is necessary to make it work