Copy link to clipboard
Copied
I want to make a game where it randomly generates a map, and players can click objects of the map. I want something to happen to that object, and I want the game to detect which object has been clicked, and temporarily assign that object a name so that I can do things to that object, I want the name to overwrite when I click a new object, and want to be able to retreive what I have done to the other objects. Any help would be appreciated.
Thanks, you pointed me in the right direction, here was my result:
public var target
public function DirtBlock() { //dirt block spawned
trace("SPAWNED")
this.addEventListener(MouseEvent.CLICK,fl_click)
}
function fl_click(event:MouseEvent):void { //dirt block clicked
var dirtblock:DirtBlock = new DirtBlock();
trace("CLICKED")
trace(event.currentTarget) //traces which object was clicked(Object, dirtblo
...Copy link to clipboard
Copied
You can use the target or currentTarget (if you assign listeners to each object) property of the clicking event to determine which object has been clicked and to manipulate that object.
Copy link to clipboard
Copied
Would there be a way to use a loop to add event listeners to each object? (I could have thousands of objects)
Copy link to clipboard
Copied
Sure. If you create the objects dynamically you can add the listeners while creating the objects. They could all share the same event handler function if they will all be processed in a similar manner.
Copy link to clipboard
Copied
Thanks, you pointed me in the right direction, here was my result:
public var target
public function DirtBlock() { //dirt block spawned
trace("SPAWNED")
this.addEventListener(MouseEvent.CLICK,fl_click)
}
function fl_click(event:MouseEvent):void { //dirt block clicked
var dirtblock:DirtBlock = new DirtBlock();
trace("CLICKED")
trace(event.currentTarget) //traces which object was clicked(Object, dirtblock)
target = event.currentTarget// sets the object to "target" so it can be manipulated
target.visible = false
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more