Highlighted

TypeError: Error #1010: A term is undefined and has no properties.

New Here ,
May 28, 2020

Copy link to clipboard

Copied

Hi, I'm trying to make a game where the character "eats" candy. So when it collides with the candy, the candy in the array should disappear or be removed. Below is my code for removing. I keep receiving an error message that states "TypeError: Error #1010: A term is undefined and has no properties." Please help me. Thank you.

 

stage.addEventListener(Event.ENTER_FRAME, duplicateCandy);

var myCandies:Array = new Array();
var candyCount:int = 0;
var candySprite:Sprite;
//"candy" is the linkage name in the library
var myCandy:candy;

function duplicateCandy(candyEvent:Event) {
if (candyCount < 5){
candySprite = new Sprite();
stage.addChild(candySprite);
myCandy = new candy();
candySprite.addChild(myCandy);
candySprite.x = Math.random() * stage.width;
candySprite.y = Math.random() * stage.height;

candySprite.width = 50;
candySprite.height = 50;

var blnColorChange:ColorTransform = new ColorTransform();

blnColorChange.blueOffset = (Math.random() * 510) - 255;
blnColorChange.greenOffset = (Math.random() * 510) - 255;
blnColorChange.redOffset = (Math.random() * 510) - 255;

candySprite.transform.colorTransform = blnColorChange;

myCandies[candyCount] = candySprite;
candyCount += 1;
if(candyCount >= 1){
stage.addEventListener(Event.ENTER_FRAME,moveCandy);
}
}
}

function moveCandy(canEvent:Event){
for(var i:int = 0; i < myCandies.length;i++){
myCandies[i].x -= 10;

if (myCandies[i].x < 0){
myCandies[i].x = stage.width;
}
}

for (var k:int = 0; k < myCandies.length;k++)
{
if (myCandies[k].hitTestObject(om))
{
stage.removeChild(myCandies[k]);
myCandies.splice(k, 1);

}
if(myCandies[k].y > 400)
{
stage.removeChild(myCandies[k]);
myCandies.splice(k, 1)

}

}
}

Views

72

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

TypeError: Error #1010: A term is undefined and has no properties.

New Here ,
May 28, 2020

Copy link to clipboard

Copied

Hi, I'm trying to make a game where the character "eats" candy. So when it collides with the candy, the candy in the array should disappear or be removed. Below is my code for removing. I keep receiving an error message that states "TypeError: Error #1010: A term is undefined and has no properties." Please help me. Thank you.

 

stage.addEventListener(Event.ENTER_FRAME, duplicateCandy);

var myCandies:Array = new Array();
var candyCount:int = 0;
var candySprite:Sprite;
//"candy" is the linkage name in the library
var myCandy:candy;

function duplicateCandy(candyEvent:Event) {
if (candyCount < 5){
candySprite = new Sprite();
stage.addChild(candySprite);
myCandy = new candy();
candySprite.addChild(myCandy);
candySprite.x = Math.random() * stage.width;
candySprite.y = Math.random() * stage.height;

candySprite.width = 50;
candySprite.height = 50;

var blnColorChange:ColorTransform = new ColorTransform();

blnColorChange.blueOffset = (Math.random() * 510) - 255;
blnColorChange.greenOffset = (Math.random() * 510) - 255;
blnColorChange.redOffset = (Math.random() * 510) - 255;

candySprite.transform.colorTransform = blnColorChange;

myCandies[candyCount] = candySprite;
candyCount += 1;
if(candyCount >= 1){
stage.addEventListener(Event.ENTER_FRAME,moveCandy);
}
}
}

function moveCandy(canEvent:Event){
for(var i:int = 0; i < myCandies.length;i++){
myCandies[i].x -= 10;

if (myCandies[i].x < 0){
myCandies[i].x = stage.width;
}
}

for (var k:int = 0; k < myCandies.length;k++)
{
if (myCandies[k].hitTestObject(om))
{
stage.removeChild(myCandies[k]);
myCandies.splice(k, 1);

}
if(myCandies[k].y > 400)
{
stage.removeChild(myCandies[k]);
myCandies.splice(k, 1)

}

}
}

Views

73

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
New Here ,
May 28, 2020

Copy link to clipboard

Copied

Also, om is the instance name for the character. myCandies is the array of candies. 

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...
Most Valuable Participant ,
May 28, 2020

Copy link to clipboard

Copied

Which Adobe app do you use?

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...