这里我试图在showMe()
中获取目标的ID。例如,当我单击按钮或图像面板的showMe()
函数首先执行时。在这里,我想捕获按钮/图像的ID。
private function init():void
{
pnl.addEventListener(MouseEvent.MOUSE_DOWN,showMe);
}
private function showMe(eve:MouseEvent):void
{
Alert.show("Hello");
}
<s:Panel id="pnl" height="400" width="700" creationComplete="init()">
<s:Button id="btn1" label="showParents"/>
<mx:Image id="img1" source="markupIndicator.png" buttonMode="true"/>
</s:Panel>
感谢任何帮助。
答案 0 :(得分:3)
为什么你需要捕获面板的mouseDown
并尝试获取内部控件的ID,但是你可以这样改变你的代码,这不是很清楚:
private function init():void
{
pnl.addEventListener(MouseEvent.MOUSE_DOWN,showMe);
}
private function showMe(eve:MouseEvent):void
{
Alert.show("Hello " + eve.currentTarget.id);
}
private function showMyID(eve:MouseEvent):void
{
showMe(eve);
}
<s:Panel id="pnl" height="400" width="700" >
<s:Button id="btn1" label="showParents" click="showMyID(event)"/>
<mx:Image id="img1" source="markupIndicator.png" click="showMyID(event)" buttonMode="true"/>
</s:Panel>
答案 1 :(得分:2)
我认为应该有效:
private function init():void
{
pn1background.addEventListener(MouseEvent.MOUSE_DOWN,showMe);
btn1.addEventListener(MouseEvent.MOUSE_DOWN,showMe);
img1.addEventListener(MouseEvent.MOUSE_DOWN,showMe);
}
private function showMe(eve:MouseEvent):void
{
trace(eve.currentTarget.id);
}
<s:Panel id="pnl" height="400" width="700" >
<s:Button id="btn1" label="showParents"/>
<mx:Image id="img1" source="markupIndicator.png" buttonMode="true"/>
<s:Panel id="pn1background" height="400" width="700" / >
</s:Panel>