all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

zoom onClipEvent (mouseDown) issue



zoom onClipEvent (mouseDown) issue Eruditorium
8/7/2005 8:46:15 PM
flash actionscript: Please can anyone with advanced knowledge of Actionscript please help me with
my code (shown below) in respect to a requirement for zooming?

I'm creating a flash animation in which I'd like to 'zoom' in and out of a
movie clip when the mouse is held. I only want to zoom into the movieclip if
the mouse is being held down and if released the movie should zoom back out.

I'm using someone else's code (shown below) which gives me the ability to zoom
into a point where the cursor is clicked. If the mouse is clicked a second time
it returns back to original resolution. The code uses onClipEvent (mouseDown)
rather than this.hitTest to ensure the zoom goes to the area the cursor is
positioned.

Is it possible to adapt this code so rather than just zooming to a set
magnification and stopping, it zooms only if the mouse is held down, and
returns to original resolution on the mouse is released?

The .fla for the code I am using is at:

[url]http://www.flashkit.com/movies/Effects/Other/Auto_zoo-T_Norman-6578/index.p
hp[/url]

many thanks in advance..



actions assigned to cursor:

*/note:
"zoom_this" is the instance name for the movie being zoomed.)*/


onClipEvent (mouseDown) {
if (i>0) {
return;
}

zoom = true;
dir == 1 ? (dir=-1) : (dir=1);
if (dir == 1) {
pt = {x:_root.zoom_this._xmouse, y:_root.zoom_this._ymouse};
}

onClipEvent (enterFrame) {
if (!zoom) {
return;
}
_root.zoom_this._xscale += dir*i*100/8;
_root.zoom_this._yscale += dir*i*100/8;
var pt2 = {x:pt.x, y:pt.y};
_root.zoom_this.localToGlobal(pt2);
_root.zoom_this._x -= (pt2.x-pt.x);
_root.zoom_this._y -= (pt2.y-pt.y);
i++;
if (i == 10) {
zoom = false;
i = 0;
}
}


Thanks
[URL=http://www.xstasis.net/]xstasis[/URL]

Re: zoom onClipEvent (mouseDown) issue Eruditorium
8/10/2005 2:30:36 AM
I go the solution from T. Norman of http://ntdesigns.net


code:



/*

Auto Zoom Function with scroll
T. Norman
http://ntdesigns.net

*/

myZoom = function (myDepth) {
if (myDepth == "deep") {
myDepth = 4;
} else if (myDepth == "medium") {
myDepth = 8;
} else if (myDepth == "light") {
// default
myDepth = 12;
}

trace(myDepth);
_root.onMouseDown = function() {
if (k>0) {
return;
}
zoom = true;
dir == 1 ? (dir=-1) : (dir=1);
if (dir == 1) {
pt = {x:_root._xmouse, y:_root._ymouse};
scale = true;

}
if (dir == -1) {
scale = false;
}
}

_root.onMouseUp = function() {
if (k>0) {
return;
zoom = false;

}
dir == 1 ? (dir=-1) : (dir=1);
zoom = true;

}
this.onEnterFrame = function() {
if (!zoom) {
return;
}
_root._xscale += dir*k*50/myDepth;
_root._yscale += dir*k*50/myDepth;
var pt2 = {x:pt.x, y:pt.y};
_root.localToGlobal(pt2);
_root._x -= (pt2.x-pt.x);
_root._y -= (pt2.y-pt.y);
k++;

if (k == 8) {
zoom = false;
k = 0;
}
}
}

//Usage

myZoom("medium");



-------------------------------------
notes:
The variable "k" is used as an increment in the scale equation.....

_root._xscale += dir*k*50/myDepth;

the if statment just resets the increment variable to 0 if it reaches 8. The
variable itself just acts as a counter. The direction of the zoom determines
whether the scale is in or out. If dir = -1... the scale would be the same
as....

_root._xscale-=value

if dir=1........

_root._xscale+=value
--------------------------------------




Here's my application of the effect if your interested:
[URL=http://www.xstasis.org/x5/x5-4door.htm]Disco penguin[/URL]

Regards,
[URL=http://www.xstasis.org]xstasis[/URL]
AddThis Social Bookmark Button