dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: zoom/pan- back to this again...

  1. #1
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707

    zoom/pan- back to this again...

    ok..i am happy with my panning script, while not even close to perfect, it will work fine for the learnign curve. The zoom is the part driving me nuts. Ultimately, i would like to be able to pan around, and then zoom to the point where i click on the mc. For those interested, here is the layout:
    • box inside mcZoom.

    • box moves from a listener, and moves according to _xmouse/_ymouse location on the stage.

    • i thought it best to have only mcZoom increase scale when clicked.



    as you can guess, the result is the mcZoom increases , but not to where my mouse clicked...how can i offset my zoom function to zoom to exactly the location of the click?
    Code:
    //after click
    function zoom() {
    	centerX = sw/2;
    	centerY = sh/2;
    	pointX = _xmouse;
    	pointY = _ymouse;
    	dx = (pointX-box._x)*2;
    	dy = (pointY-box._y)*2;
    	dist = Math.sqrt(dx+dy);
    	targX = box._x-dist;
    	targY = box._y-dist;
    	zooming = !zooming;
    	delete box.onEnterFrame;
    	Mouse.removeListener(oL);
    	if (zooming) {
    		delete box.onEnterFrame;
    		box._x = box._x-dist;
    		box._y = box._y-dist;
    		holder.onEnterFrame = function() {
    			holder._xscale = holder._yscale += 10;
    			if (holder._xscale>targZoom) {
    				delete holder.onEnterFrame;
    			}
    		};
    	}
    	if (!zooming) {
    		holder.onEnterFrame = function() {
    			holder._xscale = holder._yscale -= 10;
    			if (holder._xscale<=100) {
    				Mouse.addListener(oL);
    				delete this.onEnterFrame;
    			}
    		};
    	}
    }

  2. #2
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    still no thoughts on this?

  3. #3
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    try NTD's zoom script... it allows different levels of zooming, you can edit it so that you can click anywhere and zoom on that location.. it's pretty flawless.. very functional.
    Code:
    /*
    
            Auto Zoom Function
        T. Norman
            http://ntdesigns.net
    
    */
    
    var k = 0;
    
    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};
                    }
            };
            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;
                    }
            };
    };
    
    myZoom("medium");
    here's an example of it in use... this was a file i put togteher for someone here on FK. it uses a regular click to move the plane.. .then double click on the map to zoom in on that location.

    http://artofficialintel.com/downloads/dash_To_example/
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  4. #4
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    ohhh ohh...CAN OF WORMS madzigian!!!!

    so, after a couple tweeks, the script works like a charm...BUT, i don't get two things...the use of the return statement, and the big throw off for me, the localToGlobal expression...what is that about? i read the help file, but i don't get it completely....how does that apply in this method?

    dang, why can't i write scripts like that?

  5. #5
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    localToGlobal : Method; converts the point object from the movie clip’s (local) coordinates to the Stage (global) coordinates.

    localToGlobal makes it so if you are zooming a movieclip within a movieclip, it keeps it's global position when scaling, so the clip stays centered, and doesn't move off stage.

    as for why return is used and how/why it works where it's used.... i don't have a clue. lol


    You might want to get in touch with NTD about that.. since he wrote it...he'd know
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  6. #6
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Removing any helpful previous posts I mistakenly contributed to these forums.

    See ya FK'ers
    Last edited by NTD; 10-19-2006 at 06:17 AM.

  7. #7
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    NTD...totally apprecaiate that simple explanation of return...that gives me a whole new perspective. i'm going to have to play with return doing some simple exercises...thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center