<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>
您好。根据上面的代码,我试图将点击的BitmapImage的id传递给handleClick函数。我这样做的最佳方式是什么?
由于
答案 0 :(得分:1)
无法处理BitmapImage的点击,您需要将其放在Group或其他可以处理它的容器中,下面的示例将适合您:
<![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>
答案 1 :(得分:0)
click="handleClick(event)"
...handleClick(event:Event)
{
trace(event.target.id); // this is what you want
}