Hi everyone…
I have modified the code from the Interactive Image Panning AS3 version (found here) and I have come to a standstill.
If you look at my .fla (link) or the image ([URL=“http://img13.imageshack.us/img13/214/examplepanorama.jpg”]link) you can see its not a rectangle but has two of the top corners cut off. So it can’t really be panned using the usual method because the corners need to be avoided.
I have managed to trace ‘white’ or ‘not white’ when the areas i don’t want panned are visible but I can’t figure out how to get the scrolling to stop! My code is as follows:
import flash.display.*;
import flash.events.*;
constrainedMove(bg_mc, 2, 2);
function constrainedMove(target:MovieClip, speed:Number, dir:int){
var mousePercent:Number = mouseX / stage.stageWidth;
var mousePercenty:Number = mouseY / stage.stageHeight;
stage.addEventListener(MouseEvent.MOUSE_MOVE, panImage);
target.cacheAsBitmap = true;
function panImage(E:MouseEvent):void {
var mSpeed:Number;
var mSpeedy:Number;
mousePercent = mouseX / stage.stageWidth;
mousePercenty = mouseY / stage.stageHeight;
if (dir == 1) {
mSpeed = 1 - mousePercent;
mSpeedy = 1 - mousePercenty;
} else {
mSpeed = mousePercent;
mSpeedy = mousePercenty;
}
target.destX = Math.max(-((target.width - stage.stageWidth) * mSpeed));
target.destY = Math.min(-((target.height - stage.stageHeight) * mSpeedy));
if(target.hasEventListener(Event.ENTER_FRAME)){
target.removeEventListener(Event.ENTER_FRAME, del);
}
target.addEventListener(Event.ENTER_FRAME, del);
E.updateAfterEvent();
}
function del(E:Event):void {
var white:Boolean;
if((target.y > -512 && target.x < -2219)||(target.y > -539 && target.x > -867.3)) {
white = true; trace("white area");
} else {
white = false; trace("not white area");
}
if ((Math.abs(target.x - target.destX) <= 1) || (white == true)) {
target.x = Math.max(target.destX);
target.removeEventListener(Event.ENTER_FRAME, arguments.callee);
} else if (white==false) {
target.x += (target.destX - target.x) * (speed / 100);
}
if ((Math.abs(target.y - target.destY) <= 1) || (white == true)) {
target.y = Math.min(target.destY);
target.removeEventListener(Event.ENTER_FRAME, arguments.callee);
} else if (white==false) {
target.y += (target.destY - target.y) * (speed / 100);
}
}
}
The if((target.y > -512 && target.x < -2219)||(target.y > -539 && target.x > -867.3)) part detects if the empty part of the image is being showed or not but I don’t know what to change so that it doesn’t carry on scrolling.
If anyone could give me an idea it would be really helpful because I can’t find any information such as tutorials or forum posts about this specific problem…
Thanks.