views:

107

answers:

1
package com.test{
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.test.CreateRoundRectButton;
    import flash.events.*;
    import flash.net.*;

    public class DetailView extends MovieClip {
     private var detailPanel:MovieClip=new MovieClip();
     private var detailData:Object;
     private var closeBtn:Sprite;
     private var DetailForm:DetailViewForm=new DetailViewForm();

     public function DetailView() {

      createPanel();
      addChild(detailPanel)
      detailPanel.addChild(DetailForm);
     }
     private function createPanel()
     {

      closeBtn=new CreateRoundRectButton(30,30,10,1,0xFFFFFF,"X",0x000000);
      closeBtn.x=DetailForm.width - 25;
      closeBtn.y=2;
      closeBtn.addEventListener(MouseEvent.MOUSE_UP, closePanel,false,0,true);
      DetailForm.addChild(closeBtn)
     }

     public function closePanel(evt:MouseEvent) {
      removeChild(evt.currentTarget)
     }
    }
}

How can i remove the child of this class. when i press on the close button it needs to be remove the window. But am not getting this event properly. how can i remove this.

+3  A: 

You seem to have a misunderstanding of what Event.currentTarget is meant to be (or it's just a coding error). At the time closePanel is called as a result of the mouse up on closeBtn the value of evt.currentTarget is closeBtn (since it is the object to which you added the listener, it is the object handling the event). Since closeBtn is not a child of DetailView you won't see anything happen. In fact, if you were to run a debug build of your code in a debug player you'll see that the removeChild call results in an exception.

Assuming that you want the detailPanel to be removed then you can simply disregard the currentTarget and remove what you already know you want to remove:

public function closePanel(evt:MouseEvent) {
    removeChild(detailPanel);
}

OR ... Since MOUSE_UP bubbles you can add the listener to the detailPanel and evt.currentTarget will be the detailPanel so the removeChild call will work:

detailPanel.addEventListener(MouseEvent.MOUSE_UP, closePanel, false, 0, true);
imaginaryboy