1 Reply Latest reply on Jul 17, 2006 3:47 AM by Popeye the Sailorman

    Stretching a Sprite/Drawing

      I am trying to stretch (as opposed to scale) a sprite. I come up with the code below which seems to be very similar to examples I have seen in Flash. This code draws a rectangle and a handle (a small square). I use the dragging of the small square to redraw rectangle. I works mostly. I see some problem

      1- Rectagle is not strecthing smoothly but jitters a lot.
      2- Sometime the handle moves fasters the rectangle refreshes itself.
      3- It would be nice to constrain the movement of the handle to horizontal. I could not find a simple way to do this

      What would be a better way to implement this functionality?

      Code is below, you can drop in to any Application.

      Thanks..

      package as3.drawing
      {
      import flash.display.Sprite;
      import flash.events.MouseEvent;

      public class TDCInteractiveObject extends Sprite
      {
      private var shp:Sprite = new Sprite();
      private var shpHandle:Sprite = new Sprite();
      public function TDCInteractiveObject()
      {
      super();
      this.drawShape(200);
      this.drawHandle();

      shpHandle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
      shpHandle.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
      this.addChild(shp);
      this.addChild(shpHandle);
      }
      private function drawShape(width:int):void{
      shp.graphics.clear();
      shp.graphics.beginFill(0x00FF00);
      shp.graphics.lineStyle(2, 0xFF0000);
      shp.graphics.drawRect(100,100,width,200);
      shp.graphics.endFill();
      }
      private function drawHandle():void{
      shpHandle.graphics.beginFill(0x0000FF);
      shpHandle.graphics.drawRect(300-10,200,20,20);
      shpHandle.graphics.endFill();
      }
      private function mouseDownHandler(event:MouseEvent):void {
      shpHandle.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
      shpHandle.startDrag(false);
      }
      private function mouseUpHandler(event:MouseEvent):void {
      shpHandle.stopDrag();
      shpHandle.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
      //Redraw one more time to make sure handle and rectangle are in synch.
      drawShape(200+shpHandle.x);
      }
      private function mouseMoveHandler(event:MouseEvent):void {
      drawShape(200+shpHandle.x);
      event.updateAfterEvent();
      }
      }
      }