0

我有一个滚动列表,当用户单击(MOUSE_DOWN)一个项目时,我希望该项目的右侧出现一个“删除”图标。

我的滚动列表的代码是这样的:

private function dataLoaded(event:Event):void {
            // this holds the loaded xml data //
            data = new XML(event.target.data);
            //items properties call - add other calls to master properties later on//
            items = data.item;
            // parsing of each ingredient//
            for (var i = 0; i < items.length(); i++) {
                // instantiation of mcItem (the stage for each item)
                _item = new Item();
                // sets //over// layer to invisible / transparent //
                _item.item_btn_over.alpha = 0;
                // creates the var itemTextField //
                _itemTextField = new TextField();
                // _itemTextField visual attributes //
                _itemTextField.x = _textFieldXPosition + _textFieldPaddingLeft;
                _itemTextField.y = _textFieldYPosition;
                _itemTextField.selectable = true;
                _itemTextField.wordWrap = true;
                _itemTextField.width = _textFieldWidth;
                _itemTextField.height = _textFieldHeight;
                _itemTextField.embedFonts = true;
                _defaultFormat.color = 0x111112;
                _defaultFormat.font = _arialRounded.fontName;
                _defaultFormat.size = 18;
                _itemTextField.defaultTextFormat = _defaultFormat;
                _itemTextField.text = items[i].toString();
                //adds textfield to displaylist//
                _item.addChild(_itemTextField);
                //vertical positioning//
                _item.y = i * _itemPosition;
                _item.buttonMode = true;
                _item.mouseChildren = false;
                //adds items to container displaylist//
                _container.addChild(_item);
                _item.addEventListener(MouseEvent.MOUSE_DOWN, itemClicked);
            }

                // Input Mask//
                _mask = new Shape();
                _mask.graphics.beginFill(0xFF0000);
                _mask.graphics.drawRect(0, 0, _maskWidth, _maskHeight);
                _mask.graphics.endFill();
                // Positioning of input mask//
                // horizontal centering of input mask//
                _mask.x = stage.stageWidth / 2 - _container.width / 2;
                _mask.y = _paddingTop;
                // adds the mask onto the stage//
                addChild(_mask);
                // assigns the above mask to the container //
                _container.mask = _mask;
                // Positioning of container with the mask//
                // horizontal centering of container //
                _container.x = stage.stageWidth / 2 - _container.width / 2;
                // vertical position of container //
                _container.y = _paddingTop;

                //Container background stylings//
                _background = new Shape();
                _background.graphics.beginFill(0xFFFFFF);
                _background.graphics.drawRect(0, 0, _container.width, _container.height);
                _background.graphics.endFill();
                _container.addChildAt(_background, 0);
                //End of container background stylings//

                _container.addEventListener(MouseEvent.MOUSE_OVER, movingOver);
                _container.addEventListener(MouseEvent.MOUSE_OUT, movingOut);
            }

我有一个单独的监听器函数来监听 MOUSE_DOWN 事件,我需要帮助。我需要知道如何评估已单击的项目,然后显示一个其 AS3 链接名称为 DeleteItem 的 SimpleButton,并将其相对于该特定项目定位:

function itemClicked(event:MouseEvent):void {
    _itemTextField = new TextField();
    trace(_itemTextField.text);
    _editItem = new DeleteItem();
    addChild(_editItem);
    _editItem.x = ?????;

}
4

1 回答 1

0

使用 event.tagret - 它引用了该事件已调度的对象(在您的情况下单击了项目)

var item:Item = event.target as Item;

如果要删除某些内容,请删除对其的所有引用。如果它在舞台上使用 parent.removeChild(this)。如果您只想隐藏显示对象,请考虑使用 visible=false。

item.getChildAt(INDEX);
于 2013-04-19T13:34:22.037 回答