Zooming in UCSB Map

Zooming in UCSB Map

posted 11-26-2001 04:58 PM
Zooming is quite messy in Flash in the UCSB map because of Flash’s scaling issues. The problem lies in the fact that Flash only allows scaling from the center of an object. This means that when we zoom in on the map, it always zooms in from the center, not the center of where you are looking at. Therefore an elaborate function has been created to ‘adjust’ the map to the correct position.
The following example is for zooming in:
code:

on (release) {
//declare point objects
var oldPoint = new object();
var newPoint = new object();

//set oldPoint to center of display
oldpoint.x = 400;
oldpoint.y = 400;
//get center of display as local map coords
map.globalToLocal(oldPoint);

oldval1 = 400;
oldval2 = 400;
//get height and width before zooming.
oldWidth = map._width;
oldheight = map._height;

//get map scale
mapScale = map._width/originalWidth;
theScale = mapScale;

if (mapScale > 8.0 ) {
//then its zoomed in 8x, thats enough
s = new sound();
s.attachSound(“maxZoom”);
s.start();
}else{

//set frame depending on scale
if(mapScale > 1.5 && mapScale < 2.5){
map.gotoAndstop ( 3 );}
else if (mapScale >2.5 && mapScale < 3.0){
map.gotoAndstop (2);}
else if (mapScale >3.0){
map.gotoAndstop (1);
}
//scale map 10%
x_scale_value = int(getproperty(“/map”, _xscale)*1.1);
y_scale_value = int(getproperty(“/map”, _yscale)*1.1);
setProperty (“/map”, _xscale, x_scale_value);
setProperty (“/map”, _yscale, y_scale_value);

//set global variable to track scale
lastScale = map._width/originalWidth;
//lastSliderPos = map._xscale;

//set sliderbar in correct position
mySlider._y = (187- ((map._xscale-88)*187)/1390) + 576;

//get new height and width
newWidth = map._width;
newHeight = map._height;

//calculate point as new position on map itself
if (oldPoint.x > 0 ) {
oldPoint.x = .5 * oldWidth + oldPoint.x;
newPoint.x = oldPoint.x * newWidth / oldWidth;
newPoint.x = newPoint.x – .5 * newWidth;
}else{
oldPoint.x = .5 * oldWidth – oldPoint.x;
newPoint.x = oldPoint.x * newWidth / oldWidth;
newPoint.x = (.5 * newWidth – newPoint.x);
}
if (oldPoint.y > 0 ) {
oldPoint.y = .5 * oldHeight + oldPoint.y;
newPoint.y = oldPoint.y * newHeight / oldHeight;
newPoint.y = newPoint.y – .5 * newHeight;
}else{
oldPoint.y = .5 * oldWidth – oldPoint.y;
newPoint.y = oldPoint.y * newWidth / oldWidth;
newPoint.y = (.5 * newWidth – newPoint.y);
}

//Calculate global coordinates from map coords
map.localToGlobal(newPoint);

newX = newPoint.x;
newY = newPoint.y;

//calculate difference in newPoint to oldPoint
xdif = newPoint.x – 400;
ydif = newPOint.y – 400;

//get current x and y coords of map
currx = map._x;
curry = map._y;

//shift map xdif and ydif
if (xdif < 0 ) {
//moved left, move back to right
map._x = currx + .47 * math.abs(xdif);
}else{
//moved right, move back to left
map._x = currx – .47 * math.abs(xdif);
}
if (ydif < 0 ) {
//move back up
map._y = curry + .47 * math.abs(ydif);
}else{
//move back down
map._y = curry – .47 * math.abs(ydif);
}

//fill in text boxes
fromY = curry;
toY = map._y;
change1 = xdif;
change2 = ydif;
x_value = map._x;
y_value = map._y;

} //ends if that controls wether or not to zoom in more

}

on (rollOver) {
s = new sound();
s.attachSound(“zoomin”);
s.start();
fscommand ( “startEffect”, “TextureSoft” );
}
on (rollOut) {
fscommand (“stopEffect”, “TextureSoft”);
}

__________________

David Jones
unregistered

Leave a Reply