Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TypeError: Error #1009

New Here ,
Sep 24, 2014 Sep 24, 2014

Okay, so I know what TypeError: Error #1009 is, but I don't see what's wrong with my code.

My Code:

this.stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, groupNum);

function groupNum(event:KeyboardEvent):void

{

    if(event.keyCode != 49 && event.keyCode != 50 && event.keyCode != 51 &&

       event.keyCode != 52 && event.keyCode != 53 && event.keyCode != 54 &&

       event.keyCode != 55 && event.keyCode != 56 && event.keyCode != 57 &&

       event.keyCode != 97 && event.keyCode != 98 && event.keyCode != 99 &&

       event.keyCode != 100 && event.keyCode != 101 && event.keyCode != 102 &&

       event.keyCode != 103 && event.keyCode != 104 && event.keyCode != 105)

    {

        trace("Group #: " + GroupNum.text);

        gotoAndPlay(1, "Scene 2");

    }

}

TOPICS
ActionScript
755
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2014 Sep 24, 2014

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

For all of the code that you show I see only one object that might be at issue, the textfield you call GroupNum.

Also, the conditional you wrote could be simplified since the values are two continuous sets of numbers... one >= 50 && <= 57 and the other >= 97 and <= 105

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 26, 2014 Sep 26, 2014

How do I make it so that I can trace the text from the textfield GroupNum?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2014 Sep 26, 2014

trace(GroupNum.text);

Did you solve the 1009 error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 26, 2014 Sep 26, 2014

I think I solved it. It seems like the program wanted me to set a variable as a Textfield and make it to equal to my instance, GroupNum.

I have another error with the trace output though. I have another scene with the exact same code, but slightly different.

My Code #2:

this.stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, conditionNum);

function conditionNum(event:KeyboardEvent):void

{

    var input2:TextField = Condition;

   

    if(event.keyCode < 49 || event.keyCode > 57 && event.keyCode < 97 || event.keyCode > 105)

    {

        trace("Condition: " + input2);

        gotoAndPlay(1, "Scene 3");

    }

}

My issue with the trace output is that when this code runs, it's tracing the output from the previous scene as well.

Trace Output:

Sat Sep 27 01:19:02 GMT-0400 2014

Group #: [object TextField]

Sat Sep 27 01:19:02 GMT-0400 2014

Group #: null

Condition: [object TextField]

Sat Sep 27 01:19:02 GMT-0400 2014

Group #: null

Condition: [object TextField]

Room #: [object TextField]

I need some serious help with this because I have a deadline to meet, and this is seriously holding me back.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2014 Sep 27, 2014

If you are getting error messages and you want help with solving those error then you should provide the complete error messages in your postings.  If you havr not yet selected the option to Permit Debugging as I indicated in the first response I gave you should.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2014 Sep 27, 2014

Forget the error #1009; that's not an issue for me anymore. I just want to know why a trace from a different scene is tracing output code from the scene before; that's all I want to know for now. Could you please look a the "Trace Output" I provided, and see if you can figure out why a scene is tracing code from another scene?

SCENE 1 CODE:

this.stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, groupNum);

function groupNum(event:KeyboardEvent):void

{

     var input:Textfield = GroupNum;

    

    if(event.keyCode < 49 || event.keyCode > 57 && event.keyCode < 97 || event.keyCode > 105)

    {

        trace("Group #: " + input); //Output would be "Group #: (some number)"

        gotoAndPlay(1, "Scene 2");

    }

}

SCENE 2 CODE:

this.stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, conditionNum);

function conditionNum(event:KeyboardEvent):void

{

    var input2:TextField = Condition;

  

    if(event.keyCode < 49 || event.keyCode > 57 && event.keyCode < 97 || event.keyCode > 105)

    {

        trace("Condition #: " + input2); //Output would be "Condition #: (some number)"

        gotoAndPlay(1, "Scene 3");

    }

}

TRACE OUTPUT:

Group #: [object TextField]

Group #: null <---------------------------- THAT'S NOT SUPPOSED TO BE THERE, BUT I DON'T KNOW WHY IT POPS UP ALL THE TIME.

Condition #: [object TextField]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 28, 2014 Sep 28, 2014

If you never removed event listener from the first scene then it will still be working in the second scene.  If the textfield does not exist in the second scene it will trace null and is likely to throw the 1009 error since you are trying to target an object that does not exist in the current scene.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2014 Sep 28, 2014
LATEST

Ah, of course! I feel so stupid about not removing the event listener.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines