最简单的方法是使用一个MouseEvent
监听器。您将聆听到任何你想被点击,并告诉该功能时,触发一个事件,执行监听器:
var test:int = 0;
image.addEventListener(MouseEvent.CLICK, thisIsTest);
// Will 'listen' for mouse clicks on image and execute thisIsTest when a click happens
public function thisIsTest(e:MouseEvent):void
{
test = test + 1;
trace(test);
}
// Output on subsequent clicks
// 1
// 2
// 3
// 4
这是否意味着像你想监听连接需要可显示对象,就像一个精灵或动画片段,但如果你使用Flash,这应该不成问题。
编辑:注释中注明的进一步行动。
将图像导入到Flash,并用它来生成Sprite
或Movieclip
,并给它一个ActionScript链路ID(如类名):
// Add the image to the stage
var img:myImage = new myImage();
addChild(img);
// Assign the mouse event listener to the image
img.addEventListener(MouseEvent.CLICK, thisIsTest);
什么是输出当您添加' trace(test)''在'test = test + 1'这行之后? – James 2013-03-05 12:12:51