Highlighted

A conflict exists with inherited definition

New Here ,
Aug 21, 2019

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.

TOPICS
ActionScript

Views

433

Likes

Translate

Translate

Report

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

A conflict exists with inherited definition

New Here ,
Aug 21, 2019

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.

TOPICS
ActionScript

Views

434

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 21, 2019 0
LEGEND ,
Aug 21, 2019

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2019 0
z_ee LATEST
New Here ,
Aug 21, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2019 0