Skip to main content
Inspiring
June 5, 2009
Answered

TextField Not "Erasing"

  • June 5, 2009
  • 1 reply
  • 1273 views

I am using Actionscript 3 to dynamically add text the screen (stage) with the TextField command.  The problem is when I navigate to another screen (frame), all the text that was added stays on the screen.

Does anyone know how to make the text for only the frame that you want it to show up on?

Thanks.

Dave

This topic has been closed for replies.
Correct answer kglad

Can you help with some code to determine if it has already been added as a child?  If it is not there, I get the following error (because there is no child to remove):

TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()
at Scale6_fla::MainTimeline/frame83()
at flash.display::MovieClip/gotoAndStop()
at Scale6_fla::MainTimeline/infoBottomStopDrag()

I have been trying to come up with an if/then statement to see if it has been added as a child and then remove it if it has.  Any help with that would be greatly appreciate.

Thanks.

Dave


type your textfield so a reference always exists (until you null the reference):

var tf:TextField; // you don't need to instantiate it unless you need it.

you can then use the following:

removeF(tf);

function removeF(dobj:DisplayObject){

if(dobj.stage!=null){

dobj.parent.removeChild(dobj);

}

}

1 reply

kglad
Community Expert
Community Expert
June 5, 2009

remove your textfield (removeChild() or removeChildAt() ) if it's no longer needed on stage.  and if it's no longer needed by your swf, ready it for gc.

Inspiring
June 5, 2009

That means I have to make a reference to remove it on every frame because you can navigate anywhere you want.  Also, I get an error if i put removeChild in the first frame because it hasn't loaded yet (and therefore isn't a child yet)

Thanks.

Dave

kglad
Community Expert
Community Expert
June 5, 2009

that wouldn't work and would be burdensome.

how do you navigate away from that frame?  clicking a button?