0
votes

Good evening!

I'm currently working on a hangman project. All the menus works fine, but the one thing that does not run smooth is disabling a button that is already been pressed. What I want is a blank tile over the tile with the letter already pushed. Here is the code:

var inactive:Inactive;//The clip that will be used to block the keys already pressed

var icontainer:Array = new Array();//An array to store the inactive clips for effective removal

var keys:int = 0;//A variable to count the keys that are already inactive, this var indicates the number of "icontainer" to remove

function onKeyPress(e:MouseEvent):void { /* Get and Disable key */

inactive = new Inactive(); 
inactive.x = e.target.parent.x;
inactive.y = e.target.parent.y; 

addChild(inactive); 
icontainer.push(inactive); 
keys++;

}

If I trace (e.target.parent.x); I only get root1 in every case. How do I get the name of th key pressed eg. "A".

1

1 Answers

0
votes

You need to use e.currentTarget instead of e.target to get the element which is triggering the event.

Try this,

function onKeyPress(e:MouseEvent):void { /* Get and Disable key */

inactive = new Inactive(); 
inactive.x = e.currentTarget.parent.x;
inactive.y = e.currentTarget.parent.y; 

addChild(inactive); 
icontainer.push(inactive); 
keys++;
}

Hope it helps.