Clicking an object to execute a function and grab values

2 posts

Flag Post

In my strategy game when a tile is clicked, I need to reference values from that tile in the function.

I’ve tried doing it event.target code, but I’m new to that. After googling, I tried redefining a var as the value of the private var of the target.

public function x()
{
var y:int = 0;
y= y[event.Target];
// do stuff with y
}

Should I use a get function?

Thanks for any help, not sure if I’m on the right track.

 
Flag Post

try event.currentTarget instead, then cast that as whatever your tile class is.

private function OnTileClick(e:MouseEvent):void
{
    var currentTile:Tile = e.currentTarget as Tile;

    if (currentTile.propertyYouWantToCheckFor == "Cupcake")
    {
         trace("yum!");
    }
}