Skip to main content
chenjil43641795
Legend
August 8, 2018
Answered

ANCC h5 Object doesn't support property or method 'gotoAndStop'

  • August 8, 2018
  • 1 reply
  • 443 views

I want to make a key to control the movie clip's function.

But not running properly.

this.stop()
js = 0

window.addEventListener("keydown", lr, false);
function lr(e)
{
switch(e.keyCode)
{
  case 37:

   js = js -1

   name = "exportRoot.a" + js

   alert(name)

   name.gotoAndStop(2)


   break;

  case 39:
   js = js + 1
   name = "exportRoot.a" + js
   //alert(name)
   name.gotoAndStop(2)
   break;
}
}

Hint is  Object doesn't support property or method 'gotoAndStop'

    This topic has been closed for replies.
    Correct answer ClayUUID

    Of course name doesn't support gotoAndStop; name is a string, not an object reference. If you want a variable reference to an object, you have to use bracket notation.

    js++;

    name = "a" + js;

    exportRoot[name].gotoAndStop(2);

    Or just...

    exportRoot["a" + ++js].gotoAndStop(2);

    By the way, I really hope you're declaring name somewhere as a var because otherwise you're making it a global variable. That's bad.

    And you're missing semicolons at the end of all your lines of code.

    1 reply

    ClayUUIDCorrect answer
    Legend
    August 8, 2018

    Of course name doesn't support gotoAndStop; name is a string, not an object reference. If you want a variable reference to an object, you have to use bracket notation.

    js++;

    name = "a" + js;

    exportRoot[name].gotoAndStop(2);

    Or just...

    exportRoot["a" + ++js].gotoAndStop(2);

    By the way, I really hope you're declaring name somewhere as a var because otherwise you're making it a global variable. That's bad.

    And you're missing semicolons at the end of all your lines of code.

    chenjil43641795
    Legend
    August 9, 2018

    I'm sorry.

    I checked the system.

    I found out there was something wrong with my browser before the code went wrong.

    My problem is that all the code is a hint

    "Object doesn't support property or method "

    Even if I only write 1 alerts ("1").

    Found that there was a conflict between a software.

    Uninstall the software, it's all right now.

    About your help, thank you.

    Calling variables across scopes, I'm not very skilled.

    Writing habits and symbols, do have a problem, will pay attention to.