Welcome to WebmasterWorld Guest from 54.205.141.4

Forum Moderators: open

Message Too Old, No Replies

Image panning: need image to return to original position onmouseoff

Image pans left or right on mouseover, would like it to return onmouseoff

     
10:16 pm on Jul 12, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 13, 2004
posts:64
votes: 0


The following action script is used to make a panoramic image (bg_mc) slide back and forth depending on which side of the picture that the mouse is over. What I would love to enhance it with is the ability to make the image return to center when the user mouses OFF of the SWF.

Also, it needs to return as smooth as it pans. I am trying to avoid having it "snap" back immediately. I'm just getting into actionscript, so I am pretty stuck. But I'm sure an experienced actionscripter can hit this out of the park.

The code:

this.onMouseMove = function() {
constrainedMove(bg_mc, 4, 1);
};

function constrainedMove(target:MovieClip, speed:Number, dir:Number) {

var mousePercent:Number = _xmouse/Stage.width;
var mSpeed:Number;
if (dir == 0) {
[code]
mSpeed = 1-mousePercent;

} else {

mSpeed = mousePercent;

}
target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
target.onEnterFrame = function() {

if (target._x == target.destX) {

delete target.onEnterFrame;

} else {

target._x += Math.ceil((target.destX-target._x)*(speed/100));

}
};
}

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members