Skip to main content
z_ee
New Participant
August 21, 2019
Answered

A conflict exists with inherited definition

  • August 21, 2019
  • 1 reply
  • 1622 views

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);

}

}

This topic has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 21, 2019

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.

z_ee
z_eeAuthor
New Participant
August 21, 2019

Thank you! Is there a variable or edit I could use instead?