views:

136

answers:

1

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. And when the user is going to click on Yes I need to trace(x) and remove the Form from the hbox

+2  A: 

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

invertedSpear
how do you send the x from the Do() to the yesFunction() ?
Omu
I edited my response I missed that you were passing X as an argument.
invertedSpear
hmm, I see, I think that is going to work, but is there a better way of getting the value of x beneath getting it from the value of the label ?
Omu
AFAIK, When you add event listeners you can't pass any arguments (other than the automatic event argument) to the handler function. So you have to assign x to some variable somewhere so that you can reference it.
invertedSpear
can I inherit the form add a custom field where I can store the x ?
Omu
Don't see any reason why not
invertedSpear