开发者

Add a form with 2 buttons into a hbox dynamically

Let's say I have this function

function Do(x:String){}

How can I make so that each time this function is called开发者_运维技巧, it will add a form into a hbox, and that form will have 2 buttons yes and no and put x into the text of a label.

When the user is going to click on Yes I need to trace(x) and remove the Form from the hbox


use a lot of addChild methods. This should get you started:

var newForm:Form = newForm();
var yesBut:Button = new button();
var noBut:Button = new button();
var label:Label = new Label();

newform.addChild(yesBut);
newform.addChild(noBut);


yesBut.AddEventListener(MOUSE_EVENT.Click,yesFunction);
noBut.AddEventListener(MOUSE_EVENT.Click,noFunction);

label.name = "myLabel";
label.text = x;

//create your yes and no functions

private function yesFunction(event:MouseEvent):void{
    var x:String = event.currentTarget.parent.getChildByName("myLabel").text;
    trace(x);
    hbox.removeChild(event.currentTarget.parent);
}

This is off the top of my head, so some of it may need to be worked a little to function properly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜