Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to hide a TextField when clicking another button

New Here ,
May 17, 2013 May 17, 2013

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

TOPICS
ActionScript
871
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 17, 2013 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

Translate
Community Expert ,
May 17, 2013 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2013 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2013 May 22, 2013

Thank you kglad.  I've got it working on one button now, just trying to work out why it's not doing the same on some other buttons!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2013 May 22, 2013
LATEST

all your buttons should call the same function. 

because each button probably triggers different text to be displayed, you can use an object or dictionary to associate the buttons and their text:

// execute these two lines and your function once at the start of your app

var dictionary:Dictionary=new Dictionary(true);

var fl_TF:TextField;

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 = dictionary[e.currentTarget];
addChild(fl_TF);
}

////////// and for each button use something like:

button10.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);
dictionary[button10] = "Send disply to the right screen/projector";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines