i have mc with 10 objects instead of writting code for each i want same action prefermed on every clicked ob开发者_StackOverflow社区ject with 1 code is there way to do it?
You can listen for MouseEvent.CLICK on the stage, or on the parent movie clip, and the event.target variable will point to the object that was clicked:
stage.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void {
trace('clicked', event.target);
});
I'm not quite sure I fully understand what your question is, but you can use a for loop to iterate through a DisplayObjectContainer object's child DisplayObject objects. Then on each iteration you add an event listener to the current child DisplayObject object that listens for the MouseEvent.Click event.
for(var i:uint = 0; i < displayObjectContainer.numChildren; i++)
{
displayObjectContainer.getChildAt(i).addEventListener(MouseEvent.CLICK, clickHandler);
}// end for
function clickHandler(e:MouseEvent):void
{
// code to handle click event
}// end function
加载中,请稍侯......
精彩评论