homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Image panning: need image to return to original position onmouseoff
Image pans left or right on mouseover, would like it to return onmouseoff
jomoweb




msg:3393132
 10:16 pm on Jul 12, 2007 (gmt 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));

}
};
}


 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved