3 Replies Latest reply on Sep 21, 2011 12:57 PM by chriswillis100

    Custom selection box laggy

    chriswillis100

      Hey guys,

       

      I've made a little program that enables you to resize a box on the screen

       

      It's made up of 4 squares and when you move one sqaure the others move so that it still forms a box

       

      But when i move the square moderately quickly the box's all seem to lag

       

      Here is my code for moving one box

       

       

       

      var tl:Sprite = new Sprite();

      var tr:Sprite = new Sprite();

      var bl:Sprite = new Sprite();

      var br:Sprite = new Sprite();

       

       

      init()

       

       

      function init():void {

       

       

      tl.graphics.beginFill(0x00FF00, 1);

      tl.graphics.drawRect(100,100,10,10);

      tl.graphics.endFill();

      addChild(tl);

       

       

      tr.graphics.beginFill(0x00FF00, 1);

      tr.graphics.drawRect(300,100,10,10);

      tr.graphics.endFill();

      addChild(tr);

       

       

      bl.graphics.beginFill(0x00FF00, 1);

      bl.graphics.drawRect(100,300,10,10);

      bl.graphics.endFill();

      addChild(bl);

       

       

      br.graphics.beginFill(0x00FF00, 1);

      br.graphics.drawRect(300,300,10,10);

      br.graphics.endFill();

      addChild(br);

      tl.addEventListener(MouseEvent.MOUSE_DOWN, tlDown);

      }

       

       

      function tlDown(e:MouseEvent):void {

       

                tl.removeEventListener(MouseEvent.MOUSE_DOWN, tlDown);

                tl.startDrag();

                tl.addEventListener(MouseEvent.MOUSE_MOVE, tlMove);

       

      }

       

       

      function tlMove(e:MouseEvent):void {

       

                tr.y = tl.y

                bl.x = tl.x

                tl.addEventListener(MouseEvent.MOUSE_UP, tlUp);

       

      }

       

       

      function tlUp(e:MouseEvent):void {

       

                tl.removeEventListener(MouseEvent.MOUSE_UP, tlUp);

                tl.stopDrag();

                tl.addEventListener(MouseEvent.MOUSE_DOWN, tlDown);

      }

       

       

       

      tl stands for top left, br stands for bottom right .....etc

       

      How do i stop it from lagging so much?

      And is there a less long winded way of doing this?

       

      Thanks

      Chris