0
votes

This is my code and and when I trace (this[myButton]) gives me undefined, when I publish it gives me error:

TypeError: Error #1010: A term is undefined and has no properties. at MethodInfo-447()

var buttonsArray:Array = [];

for (var i:int=1;i<allContacts.length+1;i++){

var id:String = "id_";

var b:String = i.toString();

var buttonsvalue:Object =  id + b ; 

buttonsArray[i] = buttonsvalue;

this[buttonsvalue].addEventListener(MouseEvent.CLICK, display_label);

function display_label(e:MouseEvent):void {

var myButton = (e.target.name)

var mySprite:Sprite = new Sprite();

mySprite.graphics.beginFill(0xFFCC00);

mySprite.graphics.drawCircle(10, 10, 10);

mySprite.x=this[myButton].x-6;

mySprite.y=this[myButton].y-6;

addChild(mySprite);
}
1
the second line is for (var i:int=1;i<allContacts.length+1;i++){ - Nesrin
do the buttons exist? You add an eventListener to this[buttonsvalue], but i can't see if you add the button somewhere? - Marijn

1 Answers

0
votes

Try

mySprite.x=e.target.x-6;

If you use this[targetName], targetName should be the id of the displayObject,not the name of the displayObject.