2 Replies Latest reply on Dec 9, 2007 9:52 AM by jylaxx

    Movable Custom Components

    Chaos7703
      Howdy everyone, I have a custom component that controls various other things on the screen and I want users to be able to move it around/out of the way if they want. The component is based on the panel container. I've tried to adapt the examples on including manual drag and drop functionality, but without any luck. I'm not even sure that I need to use drag-and-drop because I don't want to transfer data between components, I just want to translate x & y coords. I tried to define functions that would rewrite the x & y coords if the user clicked on the component and dragged it using the mouse.x & y properties, but I didn't have any luck with that either. Perhaps I gave up too quickly, but I was thinking/hoping (based on what I have seen) that there would be a " isMovable =' true' " property. Thanks is advance, any help is greatly appreciated.
      Todd
        • 1. Re: Movable Custom Components
          David_M..
          Hi,

          If you are trying to make something based on the multiple document interface model you should give a look to the flexMDI framework.

          http://code.google.com/p/flexmdi/

          David
          • 2. Re: Movable Custom Components
            jylaxx Level 1
            I have had the same kind of problem and the solutions is as simple as this :

            private function startDragging( event : MouseEvent ) : void
            {
            if ( event.buttonDown )
            {
            bringToFront( event ) ;
            parent.addEventListener( MouseEvent.MOUSE_UP, stopDragging ) ;
            alpha = 0.5 ;
            var boundsRect : Rectangle = parent.getRect( parent ) ;
            boundsRect.width -= width ;
            boundsRect.height -= height ;
            startDrag( false, boundsRect ) ;
            }
            }

            private function stopDragging( event : MouseEvent ) : void
            {
            parent.removeEventListener( MouseEvent.MOUSE_UP, stopDragging ) ;
            alpha = 0.9 ;
            stopDrag() ;
            }

            Just use startDrag and stopDrag methods.

            JY