Hey guys
I’ve been building a sliding style image pan menu for a clients site. I’ve used the tutorial as seen here on the Kirupa site, with the addition of **Krilnon’s **extra coding he used here to help someone get the image to set itself to a certain position depending on whats clicked.
I have also set up a HitTest to check that the mouse is over a certain area of the stage (_root.hittest - this is a mc) so that it will only pan when over this area.
Now what I need to work out, is how to make the movie stop dead when you leave this area. Because currently, when you exit the mc area, it keeps panning to the last x position the mouse had.
So here’s the code so far:
onMouseMove = function () {
if (_root.hittest.hitTest(_root._xmouse, _root._ymouse, true)) {
constrainedMove(bg_mc,4,0,_xmouse);
}
};
};
_root.bg_mc.house1.onRelease = function():Void {
onMouseMove = null;
var somePosition = -220;
definedMove(bg_mc,6,somePosition);
};
_root.bg_mc.house2.onRelease = function():Void {
onMouseMove = null;
var somePosition = -780;
definedMove(bg_mc,6,somePosition);
};
_root.bg_mc.house3.onRelease = function():Void {
onMouseMove = null;
var somePosition = -1250;
definedMove(bg_mc,6,somePosition);
};
_root.bg_mc.house4.onRelease = function():Void {
onMouseMove = null;
var somePosition = -1690;
definedMove(bg_mc,6,somePosition);
};
_root.bg_mc.house5.onRelease = function():Void {
onMouseMove = null;
var somePosition = -2120;
definedMove(bg_mc,6,somePosition);
_root.slider1.gotoAndStop("none");
};
_root.bg_mc.house6.onRelease = function():Void {
onMouseMove = null;
var somePosition = -2530;
definedMove(bg_mc,6,somePosition);
_root.slider1.gotoAndStop("none");
};
_root.planViewer.view.windowClose.onRelease = function():Void {
onMouseMove = function ():Void {
constrainedMove(bg_mc,4,0,_xmouse);
};
};
function constrainedMove(target:MovieClip, speed:Number, dir:Number, sourceX:Number) {
var mousePercent:Number = sourceX/Stage.width;
var mSpeed:Number;
if (dir == 2) {
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 if (target._x>target.destX) {
target._x -= Math.ceil((target._x-target.destX)*(speed/200));
} else if (target._x<target.destX) {
target._x += Math.ceil((target.destX-target._x)*(speed/200));
}
};
}
function definedMove(target:MovieClip, speed:Number, destination:Number):Void {
target.onEnterFrame = function() {
if (target._x == destination) {
target.onEnterFrame = null;
} else if ((destination-target._x)>0) {
target._x += Math.ceil((destination-target._x)*(speed/200));
} else {
target._x += Math.floor((destination-target._x)*(speed/200));
}
};
}
and what I’ve been toying with is an else function for the top, like this…
onMouseMove = function () {
if (_root.hittest.hitTest(_root._xmouse, _root._ymouse, true)) {
constrainedMove(bg_mc,4,0,_xmouse);
} else {
onMouseMove = null;
mSpeed = 0;
};
};
Now so far, that piece does make it stop detecting the mouse movement, as ‘null’ should. However this is obviously the wrong way to go about it, because it doesn’t cut the movement speed to 0, and it doesn’t restart the function when you go back into the target area…
Has anyone done this before? Some help would be greatly appreciated.
Cheers!
[URL=“http://www.kirupa.com/forum/archive/index.php/t-245273.html”]