Copy link to clipboard
Copied
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'
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I've been doing this for 1 days.
The code still can't run after the software conflict problem is resolved
I finally found out the problem.
I'm so stupid.
Should have noticed that HTML5 started at 0.
Jump to frame 2nd is actually jump to frame 3rd
Modified into gotoAndStop (1);
It's going to run smoothly now.
Thank you for your help.
this.stop()
window.addEventListener("keydown", lr, false);
var js = 0;
function lr(e)
{
switch(e.keyCode)
{
case 37:
exportRoot["a" + js--].gotoAndStop(0);
break;
case 39:
exportRoot["a" + ++js].gotoAndStop(1);
break;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now