A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Problem with removeChild

Threaded View

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    69

    Problem with removeChild

    The code below works, but I'm having two problems. The text is not formatted on the first button clip (but is on subsequent clicks) and, more importantly, the removeChild is not working, so that instead of removing text ("John") before the next one displays ("Jimmy"), it's just adding them on after the other ("JohnJimmyJohnJimmy").

    Any thoughts? Thanks in advance

    Oh, and any way to do this more efficiently (less code within functions themselves that still shows the text ... this isn't important, just wondering)

    var textfield:TextField = new TextField();
    var myformat:TextFormat = new TextFormat();
    var clip:MovieClip = new MovieClip;
    var transManager:TransitionManager = new TransitionManager(clip);

    var XPos:uint = 24;
    var YPos:uint = 12;
    var offSet:uint = 24;

    john_btn.addEventListener(MouseEvent.CLICK, funcJohn);
    jimmy_btn.addEventListener(MouseEvent.CLICK, funcJimmy);


    function formatLetters()
    {
    myformat.color = 0x000000;
    myformat.font = "Tahoma";
    myformat.size = 36;
    myformat.bold = true;
    textfield.setTextFormat(myformat);
    textfield.background = true;
    textfield.backgroundColor = 0xFFFFFF;
    textfield.border = true;
    textfield.autoSize = TextFieldAutoSize.LEFT;
    clip.addChild(textfield);
    clip.x = XPos;
    clip.y = YPos;
    clip.bold = true;
    }



    function funcJohn(evt:MouseEvent)
    {
    formatLetters();
    textfield.appendText("John");
    parent.addChild(clip);
    transManager.startTransition ({type:Photo, direction:Transition.IN, duration:.3, easing:None.easeNone});
    transManager.startTransition ({type:Zoom, direction:Transition.IN, duration:.3, easing:Regular.easeOut});
    removeChild(clip);
    }

    function funcJimmy(evt:MouseEvent)
    {
    formatLetters();
    textfield.appendText("Jimmy");
    parent.addChild(clip);
    transManager.startTransition ({type:Photo, direction:Transition.IN, duration:.3, easing:None.easeNone});
    transManager.startTransition ({type:Zoom, direction:Transition.IN, duration:.3, easing:Regular.easeOut});
    removeChild(clip);
    }
    I'm getting this Error but don't understand it (know it has to do with the child thing: Error #2025: The supplied DisplayObject must be a child of the caller
    Last edited by Leftyplayer; 09-26-2009 at 11:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center