Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Many thanks kglad.
Would I need to create a parent first? As I've currently not got any parent's setup for my project.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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";
Find more inspiration, events, and resources on the new Adobe Community
Explore Now