title: AS3 Windows style drag and drop
body: <p>I'm making a windows style app with different windows which contain different elements. I know how to code a drag and drop function to change the position of the windows on the stage but I'd like to use a single code for all windows without repeating infinite functions. My code is:</p>
  
  <pre><code>public function fl_WindowDrag(event: MouseEvent): void {
          instance.startDrag();
      }
  
      public function fl_WindowDrop(event: MouseEvent): void {
          instance.stopDrag();
      }
  </code></pre>
  
  <p>I'd like the istance name was retrived automatically from the selected window, is it possible?
  I hope you understand my need
  Any help is well accepted
  Thanks in advance</p>
  
  <pre><code>package {
  
  import flash.display.*;
  import flash.text.*;
  import flash.events.*;
  import flash.ui.Keyboard;
  import flash.ui.Mouse;
  import flash.display.MovieClip;
  
  public class MainTimeline extends MovieClip {
  
      //Variabili
      public var VFullscreen: int = 1;
  
      //Import var        
      public var VTerminal: Terminal = new Terminal();
      public var nTerminal:String;
  
      public function MainTimeline(): void {
  
          stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
  
          //Import
  
          //Terminal
          VTerminal.x = 288;
          VTerminal.y = 384;
          stage.addChild(VTerminal);
  
  
          //Event Listeners
          //addEventListener(MouseEvent.CLICK, fl_BringToFront);
          VTerminal.addEventListener(MouseEvent.MOUSE_DOWN, fl_WindowDrag);
          VTerminal.addEventListener(MouseEvent.MOUSE_UP, fl_WindowDrop);
      }
  
      //public functions
  
      //Gestione Fullscreen
  
      public function fl_Fullscreen(event: MouseEvent): void {
          switch (VFullscreen) {
              case 0:
                  stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
                  VFullscreen = 1;
                  break;
              case 1:
                  stage.displayState = StageDisplayState.NORMAL;
                  VFullscreen = 0;
                  break;
          }
      }
  
      public function fl_FSCheck(event: Event): void {
          if (stage.displayState == StageDisplayState.NORMAL) {
              VFullscreen = 0;
          }
          if (stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE) {
              VFullscreen = 1;
          }
      }
  
      //Primo Piano Finestre
      public function fl_BringToFront(event: MouseEvent): void {
          this.addChild(event.currentTarget as DisplayObject);
      }
  
  
      public function fl_WindowDrag(event: MouseEvent): void {
          event.currentTarget.startDrag();
          nTerminal = event.currentTarget.name.toString();
          trace(nTerminal);
      }
  
      public function fl_WindowDrop(event: MouseEvent): void {
          event.currentTarget.stopDrag();
      }
  
      //Chiusura
      public function fl_Close(event: MouseEvent): void {
          stage.nativeWindow.close();
      }
  
      //Apertura/Chiusura Terminal
      public function fl_Terminal(event: MouseEvent): void {
          if (contains(VTerminal)) {
              removeChild(VTerminal);
          } else {
              VTerminal.x = 288;
              VTerminal.y = 320;
              addChild(VTerminal);
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>