Im currently creating textfields in a for loop – though in this example only creating one TextField.
My questions is, how do I remove the TextField child in another function?
What im basically doing is, create a Textfield, addchild to a container – > then the container into another position – > then removechild and another text in the container. I’ve tried something like:
removeChild( getChildByName(myTextField2) );
edit: perhaps a solution for me could also just to be able to change the text of the TextField to something else, rather than removing it and adding a new one.
public function handleTextFrames(numberOfFrames:Number, textFrame1:String, textFrame2:String, textFrame3:String, textFrame4:String):void
{
var textArray:Array = new Array(textFrame1,textFrame2,textFrame3,textFrame4);
// Creating font instance
var garageInstance:Font = new garage();
//Creating the textfield object and naming it "myTextField"
var myTextField:TextField = new TextField();
//Here we add the new textfield instance to the stage with addchild()
textContainer.alignContainer1.addChild(myTextField);
//myTextField.width = 930;
myTextField.embedFonts = true;
myTextField.multiline = true;
myTextField.wordWrap = false;
myTextField.selectable = false;
var myText:String = textArray[0];
myTextField.htmlText = myText;
//This last property for our textfield is to make it autosize with the text, aligning to the left.
myTextField.autoSize = TextFieldAutoSize.LEFT;
//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat = new TextFormat();
//Embedding font
myFormat.font = garageInstance.fontName;
myFormat.color = 0xffffff;
myFormat.size = 60;
myFormat.align = TextFormatAlign.CENTER;
//Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
myTextField.setTextFormat(myFormat);
myTextField.y = textContainer.alignContainer1.height * 0.5 - myTextField.textHeight * 0.5;
myTextField.x = payoffContainer_mc.width / 2 - myTextField.textWidth / 2;
}
What exactly do you want to do? 🙂 Because if you keep the textfields in a “global” array, that would solve it.
Let’s say you keep it in an array, called
textfields.You push everything in to this, by
Then, at any time, you can remove this by calling this function:
concerning the first element. In flash this always works:
Does this help?