Copy link to clipboard
Copied
An error pops up when im using this code to move a character in one of my games. Im using actionscript and im not sure if this coding is for HTML so it doesn't work. I'm extremely new to coding and your help is very much needed.
"A conflict exists with inherited definition flash.display:DisplayObject.root in namespace public."
var root = this;
document.addEventListener("keydown", handleKeyDown);
function handleKeyDown(event) {
//left and right arrow key
if (event.which == 37 || event.which == 39) {
var newX = root.characterGame.x + (10 * (event.which - 38));
createjs.Tween.get(root.characterGame).to({x: newX}, 1);
}
//up and down arrow key
if (event.which == 38 || event.which == 40) {
var newY = root.characterGame.y + (10 * (event.which - 39));
createjs.Tween.get(root.characterGame).to({y: newY}, 1);
}
}
From what I can see, you should probably avoid trying to create a variable named 'root'. Actionscript already has an animal by that name. Either use 'this' or don't even bother using either. AS3 already understands what 'this' is without having to say so.
Copy link to clipboard
Copied
From what I can see, you should probably avoid trying to create a variable named 'root'. Actionscript already has an animal by that name. Either use 'this' or don't even bother using either. AS3 already understands what 'this' is without having to say so.
Copy link to clipboard
Copied
Thank you! Is there a variable or edit I could use instead?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now