0 Replies Latest reply on Jun 11, 2010 10:24 AM by autokad

    Issues with Sprites and changing size

    autokad

      I want to add a graphics component to my program.

       

      What would be nice is if I could change the size of a sprite with the mouse wheel, making it larger or smaller, but when I modify the width of the sprite, its X coordinate is thrown out of wack.  If I click on the left side of the screen it barely moves.  the further right i click the more the sprite is MOVED to the right of the screen when I increase its size.  Decreasing has a similar but opposite affect. 

       

      I basically want an interactive sprite that I can change the size, color, and location with user input.  Anyone done this before? seen a place I can look at?

       

      here is my code snippets bellow:

       

      public function draw(shape:String, event:MouseEvent, size:int):void

          {

          var square:Sprite = new Sprite();

         

          if(okDraw)

          {

          square.graphics.beginFill(0xFF0000,.5);

          square.graphics.drawRect(event.stageX,event.stageY,size,size);

          square.graphics.endFill();

          square.graphics.lineStyle(2,0x000000);

          square.name=spriteIndex.toString();

          square.buttonMode=true;

          //square.useHandCursor=true;

          myCanvas.rawChildren.addChild(square);

         

       

          square.addEventListener(MouseEvent.MOUSE_DOWN, onMyMouseDown);

          square.addEventListener(MouseEvent.MOUSE_UP, onMyMouseUp);

          square.addEventListener(MouseEvent.MOUSE_WHEEL, onSpriteWheel);

         

          spriteIndex=spriteIndex+1;

          square.addEventListener(MouseEvent.CLICK, onSpriteClick);

          //square.addEventListener(event.

          }// end if

          okDraw=true;

          }// end function

       

      private function onSpriteWheel(event:MouseEvent):void

          {

                 event.target.width=event.target.width+event.delta;

          }// end func

         

          private function onSpriteClick(event:MouseEvent):void

          {

                 event.target.width=event.target.width+25;

          }// end func

         

          private function onMyMouseDown(event:MouseEvent):void

          {

                okDraw=false;

                event.target.startDrag();

          }// end func