2 Replies Latest reply on Jul 26, 2011 6:52 AM by Seglespaan

    Draggable canvas

    Seglespaan Level 1

      Hi,

       

      how can i modify this class to make the canvas draggable when the user clicks and drags the title bar. (title bar is a bad name as the bar will never contain text)

       

      Thanks

       

      Tim

       

       

      package as_classes

      {

      import flash.events.Event;

       

      import mx.containers.Canvas;

      import mx.core.IUITextField;

      import mx.core.UIComponent;

      import flash.events.MouseEvent;

       

       

      public class DraggableCanvas extends Canvas

      {

       

      protected var titleBar:UIComponent;

      protected var textField:IUITextField;

       

      public function DraggableCanvas()

      {

      super();

      }

       

      override protected function createChildren():void

      {

          super.createChildren();

       

      titleBar = new UIComponent();

      titleBar.x = 0;

      titleBar.y = 0;

      titleBar.height = 17;

      titleBar.width = 600;

      titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);

                  titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);

      addChild(titleBar);

       

       

      }

       

              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{

                  super.updateDisplayList(unscaledWidth,unscaledHeight);

              }

       

              private function handleDown(e:Event):void{

                  this.startDrag();

              }

       

              private function handleUp(e:Event):void{

                  this.stopDrag();

              }

       

      }

      }