Action Script 3.0 - MouseEvent Listener + 功能问题
Action Script 3.0 - MouseEvent Listener + function issues
我正在处理一个在舞台上有多个可点击对象的项目。
但是,当我创建以下函数时,我得到了最后定义的事件监听器。
// Event listeners
antwoordBox1.addEventListener(MouseEvent.CLICK, antwoordboxclick);
antwoordBox2.addEventListener(MouseEvent.CLICK, antwoordboxclick);
function antwoordboxclick(event:MouseEvent):void {
trace (event.currentTarget.name); // traces 'antwoordBox2' , whether I click any of the buttons.
if (event.currentTarget.name == 'antwoordBox1') {
trace('antwoordBox1 selected');
}
if (event.currentTarget.name == 'antwoordBox2') {
trace('antwoordBox2 selected');
}
currentQuestion++; // function to handle after above
trekNieuweVraag(); // another function to handle after above
}
// end of my code
无论我尝试什么,我都无法解决问题。当我使用 event.target 时,我在 antwoordBox2(或 antwoordBox1)中获取子影片剪辑名称。
希望有人能帮助我! :)
禁止鼠标与 antwoordBox 的子项交互:
antwoordBox1.mouseChildren = false;
antwoordBox2.mouseChildren = false;
注册事件侦听器:
addEventListener(MouseEvent.CLICK, antwoordboxclick);
事件处理程序内部:
if (event.target == antwoordBox1)
trace('antwoordBox1 selected');
else if (event.target == antwoordBox2)
trace('antwoordBox2 selected');
我正在处理一个在舞台上有多个可点击对象的项目。
但是,当我创建以下函数时,我得到了最后定义的事件监听器。
// Event listeners
antwoordBox1.addEventListener(MouseEvent.CLICK, antwoordboxclick);
antwoordBox2.addEventListener(MouseEvent.CLICK, antwoordboxclick);
function antwoordboxclick(event:MouseEvent):void {
trace (event.currentTarget.name); // traces 'antwoordBox2' , whether I click any of the buttons.
if (event.currentTarget.name == 'antwoordBox1') {
trace('antwoordBox1 selected');
}
if (event.currentTarget.name == 'antwoordBox2') {
trace('antwoordBox2 selected');
}
currentQuestion++; // function to handle after above
trekNieuweVraag(); // another function to handle after above
}
// end of my code
无论我尝试什么,我都无法解决问题。当我使用 event.target 时,我在 antwoordBox2(或 antwoordBox1)中获取子影片剪辑名称。
希望有人能帮助我! :)
禁止鼠标与 antwoordBox 的子项交互:
antwoordBox1.mouseChildren = false; antwoordBox2.mouseChildren = false;
注册事件侦听器:
addEventListener(MouseEvent.CLICK, antwoordboxclick);
事件处理程序内部:
if (event.target == antwoordBox1) trace('antwoordBox1 selected'); else if (event.target == antwoordBox2) trace('antwoordBox2 selected');