Skip to main content
Participant
May 17, 2013
Answered

How to hide a TextField when clicking another button

  • May 17, 2013
  • 1 reply
  • 926 views

Hello!

I've been able to generate a TextField to appear when clicking a button, but when I click on another button, to display some more information, I still have the first TextField displayed.  I've had a look around, but not been able to find anything to help me with getting the first to disappear.  Can anyone provide any ideas for this?

The code I'm using for displaying the TextField is:

button10.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;
var fl_TextToDisplay:String = "Send disply to the right screen/projector";

function fl_ClickToPosition(event:MouseEvent):void
{
fl_TF = new TextField();
fl_TF.autoSize = TextFieldAutoSize.LEFT;
fl_TF.background = true;
fl_TF.border = true;
fl_TF.x = 300;
fl_TF.y = 100;
fl_TF.text = fl_TextToDisplay;
addChild(fl_TF);
}

Many thanks in advance

This topic has been closed for replies.
Correct answer kglad

use:

button10.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;
var fl_TextToDisplay:String = "Send disply to the right screen/projector";

function fl_ClickToPosition(event:MouseEvent):void
{

if(fl_TF&&fl_TF.parent){  /

fl_TF.parent.removeChild(fl_TF);

fl_TF=null

}

fl_TF = new TextField();
fl_TF.autoSize = TextFieldAutoSize.LEFT;
fl_TF.background = true;
fl_TF.border = true;
fl_TF.x = 300;
fl_TF.y = 100;
fl_TF.text = fl_TextToDisplay;
addChild(fl_TF);
}

Many thanks in advance

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 17, 2013

use:

button10.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;
var fl_TextToDisplay:String = "Send disply to the right screen/projector";

function fl_ClickToPosition(event:MouseEvent):void
{

if(fl_TF&&fl_TF.parent){  /

fl_TF.parent.removeChild(fl_TF);

fl_TF=null

}

fl_TF = new TextField();
fl_TF.autoSize = TextFieldAutoSize.LEFT;
fl_TF.background = true;
fl_TF.border = true;
fl_TF.x = 300;
fl_TF.y = 100;
fl_TF.text = fl_TextToDisplay;
addChild(fl_TF);
}

Many thanks in advance

fishy4021Author
Participant
May 20, 2013

Many thanks kglad. 

Would I need to create a parent first? As I've currently not got any parent's setup for my project.

kglad
Community Expert
Community Expert
May 20, 2013

no.

if it's added to the displaylist, it has a parent.  if it's not added to the displaylist, it doesn't need to be removed (but you still might want to null it).