A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Offsetting x pos of the object for move

  1. #1
    aidanmack.co.uk
    Join Date
    Dec 2001
    Location
    York, UK
    Posts
    400

    resolved [RESOLVED] Offsetting x pos of the object for move

    Hi,
    Im struggling with the maths for this...

    basically if you use this...


    Code:
    function moveit(e:Event){
    	BTN.x = this.mouseX
    }
    BTN.addEventListener(MouseEvent.MOUSE_MOVE, moveit);
    "BTN"'s x will snap to the position of the mousex

    But I dont want it to snap to mouseX pos. I want it to move but offset from where the mousex is

    So I was thinking something along the lines of this...
    Code:
    import flash.events.Event;
    
    function moveit(e:Event){
    	var offset = BTN.x -this.mouseX;
    	trace(offset)
    	BTN.x = this.mouseX + offset
    }
    BTN.addEventListener(MouseEvent.MOUSE_MOVE, moveit);
    OffSet is the diffrence between the btn.x and the mousex and then I add that to that mouseX. But that doesnt work. Can some one tell me what Im doing wrong?

  2. #2
    aidanmack.co.uk
    Join Date
    Dec 2001
    Location
    York, UK
    Posts
    400
    sorry! got it! just needs the offset on mousedown, no need on mousemove.

    RESOLVED.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center