Reputation: 660
<fx:Script>
<![CDATA[
private function handleClick(id:String):void {
trace("id clicked: " + id);
if(id == "1") {
trace("1 clicked");
} else if(id=="2") {
trace("2 clicked");
} else {
trace("Nothing");
}
}
]]>
</fx:Script>
<s:Group width="100%" height="100%" click="handleClick()" >
<s:BitmapImage id="1"/>
<s:BitmapImage id="2"/>
</s:Group>
Hello. Based on the code above, I am trying to pass the id of the clicked BitmapImage to the handleClick function. What is the best way for me to do this?
Thanks
Upvotes: 0
Views: 296
Reputation: 4568
It's not possible to handle the click of the BitmapImage, you will need to put it inside a Group or other container that can handle it, the example below will work for you:
<![CDATA[
import mx.controls.Alert;
private function handleClick(event:Event):void {
var id:String = event.target.id;
trace("id clicked: " + id);
if(id == "1") {
trace("1 clicked");
} else if(id=="2") {
trace("2 clicked");
} else {
trace("Nothing");
}
}
]]>
</fx:Script>
<s:Group width="100%" height="100%" click="handleClick(event)" >
<s:Group id="b1" >
<s:BitmapImage />
</s:Group>
<s:Group id="b2" >
<s:BitmapImage />
</s:Group>
</s:Group>
Upvotes: 1
Reputation: 1
click="handleClick(event)"
...handleClick(event:Event)
{
trace(event.target.id); // this is what you want
}
Upvotes: 0