Skip to main content
November 12, 2006
Question

zoom to rectangle on movieclip

  • November 12, 2006
  • 4 replies
  • 529 views
Hi, I'm trying out Flash and would like to implement a zoom and pan like the one here: http://zeroextinction.org/pointmapper/azefiles/index.html

I am as far as generating the rectangle over my movie clip. The trouble is how to then grab the coordinates of the rectangle and zoom to it. I figured I could do it using _xscale and _yscale but its tricky for me to get the correct zoom scale and also to reposition the image so that the rectangle the user draws is exactly zoomed into. I have an mc africa_mc which has my graphics. See code below, doesnt zoom correctly. Help appreciated.
This topic has been closed for replies.

4 replies

David Stiller
Inspiring
November 15, 2006
Completely off topic: I happen to be logged in to these forums via the browser interface (very rare for me, because I prefer to use a news client). Because of this, I forgot to include my usual signature -- but I see that the forum has recognized me anyway. Funny part is, it says this is my first post, and that I joined late in 2005.

I feel young again! :)


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."
Participant
June 4, 2007
Did this issue ever get sorted, I've got myself to this exact spot and now I'm stuck.

Thanks
David Stiller
Inspiring
November 15, 2006
jgn2006,

Hey, kudos on your code so far! You've come a long way already.

> first, the _xscale and _yscale were different so the movieclip got
> distorted after the zoom; secondly, it only worked when I drag the
> zoom rectangle from top left and third it works only on the first
> zoom but not subsequent ones. I managed to fix the first two but
> now stuck with the third.

Based on what I'm seeing, that third problem makes sense. Essentially, you're starting from scratch every time, because you're deriving your scale from the height and width of the Stage, as compared with the drawn rectangle, when the mouse is released. In order to *keep* zooming, I believe you'll have to rethink that ratio variable, theScale.

Off the top of my head, I thinking you may need to compare the size of the zoom rectangle to the width and height of the Africa movie clip, not the Stage. As Africa's scale changes, you'll have to compensate your zoom rectangle measurements to decide how to zoom it further.

Does that make sense? Too vague? I can "see" an approach in my head, but to test it out and really elaborate, I'd have to put together a sample file. Unfortunately, the past several days have been pretty hectic for me.

I know you offered to provide your FLA, but I really like to go minimalist when trying to solve a problem: new FLA, only the elements that pertain to the problem. Clean slate sort of thing. Have you tried that, maybe? It often helps to "take a breather" of sorts and start over in a fresh document, without the clutter or emotional baggage of an existing project.
kglad
Community Expert
Community Expert
November 12, 2006
make sure your map has its registration point in the upper left and it's located at 0,0 to start or adjust the _x,_y for your start point.
November 12, 2006
I changed the registration to upper left but did not understand this very well:
quote:

and it's located at 0,0 to start or adjust the _x,_y for your start point.
and perhaps that is why it still does not work well. Depending on how many times I zoom and where I start drawing the rectangle, the zoom does not work as expected. Maybe I should attach the fla, but how do I do that here?
November 12, 2006
I had three problems when I tried kglad's onMouseUp suggestion: first, the _xscale and _yscale were different so the movieclip got distorted after the zoom; secondly, it only worked when I drag the zoom rectangle from top left and third it works only on the first zoom but not subsequent ones. I managed to fix the first two but now stuck with the third. Somehow on subsequent zooms something needs to be reset. Help appreciated. Here is the full code so far:
kglad
Community Expert
Community Expert
November 12, 2006
change your onMouseUp handler to:

November 12, 2006
Thanks for responding but No that didn't fix it. It still zooms but not to the area I drew the rectangle over.