我在设置精灵的子索引时遇到问题...它在程序的第一次运行时完美运行,但在第二次运行时失败。对于上下文,此函数位于一个类中,该类接受一个精灵数组并显示它们。我的问题在于setChildIndex(_selected as DisplayObject, numChildren-1);
private function enlarge(e:MouseEvent):void
{
if (!_open)
{
_selected = e.currentTarget;
_selectedOrigX = _selected.x;
_selectedOrigY = _selected.y;
_selectedID = _selected.id;
_open = true;
setChildIndex(_selected as DisplayObject, numChildren-1);
new TweenLite(_selected, 0.5, {width:984, height:640, x:0, y:0, ease:Bounce.easeOut} );
_yes = new Yes_btn();
addChild(_yes);
_no = new No_btn();
addChild(_no);
_yes.addEventListener(MouseEvent.CLICK, selected);
_no.addEventListener(MouseEvent.CLICK, cancel);
}
}
答案 0 :(得分:0)
问题在于我忘记从对象中删除以前的事件侦听器。使用以下代码,一切都能正常工作。
addEventListener(Event.REMOVED_FROM_STAGE, removed);
private function removed(e:Event):void
{
for (var i:uint; i < _objectsArray.length; i ++)
{
var object:Sprite = _objectsArray[i];
object.removeEventListener(MouseEvent.CLICK, enlarge);
}
}