1 Reply Latest reply on Dec 3, 2006 7:12 AM by HawesD

    MouseEvent.LocalX co-ordinates doesn't resize with sprite

      I'm looking into how to create a custom sprite which the mouse performs different actions depending which part of the sprite it is clicked on they are:

      1) Click and drag on the left edge able extends the box to the left
      2) Click and drag in the middle able to move the box round the screen (drag and drop)
      3) Click and drag on the right edge able to extend the box to the right.

      I've looked at a couple of ways to implement the context on the rectagle. One of them is testing where the mouse clicks on the sprite. My code for that test is this:

      private function get LeftHandRegion () : Number {return 25;}
      private function get RightHandRegion () : Number {return width - 25;}

      private function IsInLeftHandRegion(event:MouseEvent) : Boolean {return (event.localX < LeftHandRegion);}
      private function IsInRightHandRegion(event:MouseEvent) : Boolean {return (event.localX > RightHandRegion);}
      private function IsInMiddleRegion(event:MouseEvent) : Boolean {
      return (event.localX >= LeftHandRegion && event.localX <= RightHandRegion)

      If I set my original sprite size to 300 everything works as it should and I can perform all 3 actions correctly.

      However if I then streatch my rectangle to 800 the event.LocalX only goes upto the original 300 event though the sprite is now bigger so my test for the right hand region fails so I can't extend my box to the right any more.

      Does any one have any ideas?
        • 1. Re: MouseEvent.LocalX co-ordinates doesn't resize with sprite
          HawesD Level 1
          I have found a solution to this problem. On the mouseup event I remove the current resized DisplayObject from its parent.

          Then I create a new DisplayObject and pass in the parameters from the existing but resized DisplayObject.

          The new DisplayObject is then added back to the parent.

          Then everything works :D

          Code snippet is this:
          var year:YearDisplay = YearDisplay(parent);
          var newUnitDisplay = new UnitDisplay(x, y, width, height, _unit, _colour);