Skip to main content
Known Participant
December 9, 2013
Question

removeChild() via class file

  • December 9, 2013
  • 2 replies
  • 684 views

Hi,

i have a problem to delete text field via class file.

Im getting this error

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

          at flash.display::DisplayObjectContainer/removeChild()

          at dzn::DeleteTextField/deleteTF()

Can somebody help me with that?

Here is my Main.as

package 

{

     import flash.display.Sprite;

     import flash.display.*;

     import flash.events.MouseEvent;

     import flash.text.TextField;

     import flash.text.TextFormat;

 

     import dzn.InputTextField;

     import dzn.DeleteTextField;

     public class Main extends Sprite

     {

         public var ITF:InputTextField = new InputTextField;

         public var DTF:DeleteTextField = new DeleteTextField();  

         public function Main()

         {

                   // There is 2 static button on the stage "loginBtn" and "hideTf".

                    loginBtn.addEventListener(MouseEvent.CLICK, initKeyboard); // Display InputTextField           

                hideTf.addEventListener(MouseEvent.CLICK, hideTFF); // Delete InputTextField - This is working 

                    hideTf.addEventListener(MouseEvent.CLICK, DTF.deleteTF); // Call deleteTF function via class DeleteTextField to delete InputTextField - This is not working

                    // If I call deleteTF function in DeleteTextField class, then i can access function but i can't delete Text Field

         }

        

         public function initKeyboard(e:MouseEvent):void

         {

                    // When button is clicked then it creating new Input text field

                    ITF = new InputTextField();

                    addChild(ITF);

         }

 

         public function hideTFF(e:MouseEvent):void

         {

                    // When clicked then it removing Input text field

                    this.removeChild(ITF);

         }

     }

}

Here is my InputTextField.as

package dzn

{

          import flash.display.Sprite;

          import flash.events.MouseEvent;

          import flash.text.TextField;

          import flash.text.TextFormat;

 

          public class InputTextField extends Sprite

          {

                    public var txt:TextField = new TextField();

 

                    public function InputTextField()

                    {

                              txt.width = 1160;

                              txt.height = 350;

                              txt.background = true;

                              txt.backgroundColor = 0xffffff;

                              txt.border = true;

                              txt.borderColor = 0xcccccc;

                              txt.multiline = true;

                              txt.wordWrap = true;

 

                              txt.defaultTextFormat = new TextFormat("Arial", 25, 0x546770,true,null,null,null,null,"left");

                              txt.text = "PRESS HERE"

                              addChild(txt);

                              txt.x = 20;

                              txt.y = 84;

                    }

          }

}

Here is my DeleteTextField.as

package dzn

{

          import flash.display.Sprite;

          import flash.display.*;

          import flash.events.MouseEvent;

          import flash.text.TextField;

          import flash.text.TextFormat;

 

          import dzn.InputTextField;

 

          public class DeleteTextField extends Sprite

          {

               public var ITF:InputTextField;

 

               public function DeleteTextField() {

                         ITF = new InputTextField();

               }

 

               public function deleteTF(e:MouseEvent):void

               {

                         this.removeChild(ITF); // This is not working

               }

          }

}

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
December 9, 2013

i'm not sure why you have a deletetextifeld class.  it serves no purpose.

normally, a textfield extending class would handle the textfield's creation, text assignment and retrieval and removal.  you should rethink your setup.

Known Participant
December 9, 2013

Here is a story.

Text from textfield i will send to SQL via php script. (but this is another story).

When you click inside the textfield, an virtual keyboard will appearing, and there is send button too.

That i want is to send text and delete textfield when you click at the send button.

So, i'm adding text field in Main.as via ITF = new InputTextField(); addChild(ITF);

Textfield is displaying correctly.

And i know that easiest way to delete this textfield is to call hideTFF function which is in main class.


But i don't need to delete it via main class. I need to delete it via another class because virtaul keyboard and send button is in another class.

And when im trying to delete it via another class im getting error.

I'm suppose that problem is in this.removeChild(ITF); because flash do not know who is a parent to this child and can't remove it.

So if you can give me tips how to add text field and delete it from another class it will help.

Ned Murphy
Legend
December 10, 2013

See my first reply.

Ned Murphy
Legend
December 9, 2013

In your DeleteTextField.as class code you never addChild(ITF), so there is no child to remove.