Actionscript 3 AS3删除精灵对象的多个子对象
我在应用程序中有一个按钮,用户可以单击该按钮添加多个输入字段。函数如下所示Actionscript 3 AS3删除精灵对象的多个子对象,actionscript-3,Actionscript 3,我在应用程序中有一个按钮,用户可以单击该按钮添加多个输入字段。函数如下所示 private var fieldHolder:Sprite = new Sprite(); private function addInviteFriend(event:starling.events.Event):void { this.newFriendInvite = new TextInput(); this.newFriendInvite.backgroundSkin = new Quad(
private var fieldHolder:Sprite = new Sprite();
private function addInviteFriend(event:starling.events.Event):void
{
this.newFriendInvite = new TextInput();
this.newFriendInvite.backgroundSkin = new Quad(Constants.STAGE_WIDTH - 80, 30, 0xd0d0d1);
this.newFriendInvite.width = Constants.STAGE_WIDTH - 110;
this.newFriendInvite.height = 30;
this.newFriendInvite.text = "";
this.fieldHolder.addChild(this.newFriendInvite);
this.newFriendInvite.x = 0;
this.newFriendInvite.y = this.fieldHolder.height;
this.removeInvitedFriend = new Button();
this.removeInvitedFriend.defaultSkin = new Image(Assets.getAtlasTexture("btn-delete"));
this.fieldHolder.addChild(this.removeInvitedFriend);
this.removeInvitedFriend.x = int((this.newFriendInvite.x + this.newFriendInvite.width) - this.newFriendInvite.defaultSkin.width);
this.removeInvitedFriend.y = int(this.newFriendInvite.y);
this.removeInvitedFriend.addEventListener(starling.events.Event.TRIGGERED, removeInviteFriendClick);
this.addInviteFriendButton.y = this.fieldHolder.y + this.fieldHolder.height + 30 + 1;
}
private function removeInviteFriendClick(event:starling.events.Event):void
{
var child:Sprite = event.currentTarget as Sprite;
this.fieldHolder.removeChild(child);
}
一切都很好,我可以添加多个输入字段,但问题是,当我单击删除按钮时,只有按钮本身被删除,而不是文本输入字段。我知道为什么只有按钮被删除,但我不知道如何在removeChild进程中包含textinput
我尝试创建另一个精灵来保存fieldHolder的所有实例,但没有成功。我也试着让孩子们离开,但也没用
谢谢尝试将这两个元素添加到一个容器中,然后调用
removeChildren
private var fieldHolder:Sprite = new Sprite();
private function addInviteFriend(event:starling.events.Event):void
{
var container:Sprite = new Sprite();
this.newFriendInvite = new TextInput();
this.newFriendInvite.backgroundSkin = new Quad(Constants.STAGE_WIDTH - 80, 30, 0xd0d0d1);
this.newFriendInvite.width = Constants.STAGE_WIDTH - 110;
this.newFriendInvite.height = 30;
this.newFriendInvite.text = "";
this.newFriendInvite.x = 0;
this.newFriendInvite.y = this.fieldHolder.height;
container.addChild(this.newFriendInvite);
this.removeInvitedFriend = new Button();
this.removeInvitedFriend.defaultSkin = new Image(Assets.getAtlasTexture("btn-delete"));
this.removeInvitedFriend.x = int((this.newFriendInvite.x + this.newFriendInvite.width) - this.newFriendInvite.defaultSkin.width);
this.removeInvitedFriend.y = int(this.newFriendInvite.y);
this.removeInvitedFriend.addEventListener(starling.events.Event.TRIGGERED, removeInviteFriendClick);
container.addChild(this.removeInvitedFriend);
this.addInviteFriendButton.y = this.fieldHolder.y + this.fieldHolder.height + 30 + 1;
this.fieldHolder.addChild(container);
}
private function removeInviteFriendClick(event:starling.events.Event):void
{
var child:Sprite = event.currentTarget as Sprite;
child.parent.removeChildren();
}
调用
this.fiedHolder.removeChildren()时会发生什么
在removeinveitefriendclick
中,不会删除子项?它会删除所有输入和删除按钮,而不仅仅是单击的“组”