A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: panning image with AS

  1. #1
    Senior Member skdzines's Avatar
    Join Date
    Sep 2003
    Posts
    301

    panning image with AS

    I am using the following code to pan an image based on the mouse position. All works fine except I want the image to slide to the correct position with easing if you move the mouse off of the stage and then reenter the mouse in a different position from when you left. Right now, what it does is snaps to the mouse instead of sliding to it.

    Code:
    _root.createEmptyMovieClip("holder", 1);
    holder.attachMovie("image", "image", 1);
    holder._x = 0;
    holder._y = 0;
    slope = (Stage.width - holder._width)/Stage.width;
    vertSlope = (Stage.height - holder._height)/Stage.height;
    
    curXPos = holder._x;
    curYPos = holder._y;
    
    _root.onMouseMove = function(){	
    	_root.onEnterFrame = function(){
    		_root.holder._x = slope*_xmouse;
    		_root.holder._y = vertSlope*_ymouse;
    		
    		curXPos = _root.holder._x = slope*_xmouse;
    		curYPos = _root.holder._y = vertSlope*_ymouse;
    		trace("x:" + curXPos);
    		trace("y:" + curYPos);
    		delete(this.onEnterFrame);
    	}
    }
    Can somebody take a look or give me an idea as to how I can make it slide to the mouse from the images current position with easing instead of snapping to it? Any help is greatly appreciated.

  2. #2
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    Hi
    Maybe this as a workaround....edit the stage size restraints to suit...
    Example:
    Put this on a movieclip...
    code:
    onClipEvent (enterFrame) {
    // x movement
    mx = _root._xmouse;
    if (mx<_x) {
    dx = _x-mx;
    } else {
    dx = mx-_x;
    }
    moveSpeedx = dx/3;
    if (mx<_x) {
    _x = _x-moveSpeedx;
    } else {
    _x = _x+moveSpeedx;
    }
    // y movement
    my = _root._ymouse;
    if (my<_y) {
    dy = _y-my;
    } else {
    dy = my-_y;
    }
    moveSpeedy = dy/3;
    if (my<_y) {
    _y = _y-moveSpeedy;
    } else {
    _y = _y+moveSpeedy;
    }
    //stage size restraints
    if (this._x>480) {
    this._x = 480;
    }
    if (this._x<0) {
    this._x = 0;
    }
    if (this._y<0) {
    this._y = 0;
    }
    if (this._y>330) {
    this._y = 330;
    }
    }


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