0 Replies Latest reply on Aug 17, 2006 3:53 PM by shaunperry

    scroll movieclip on zoom area problem

    shaunperry
      Hi there

      I have a script which scrolls a larger image using the scrollrect function. when you click on the left mouse button the image is enlarged or zoomed into. but it loses the position that you originally clicked on. i guess i have to update the x and y coordinates at the same time as i alter the xscale and yscale but i m having trouble with the calculation. can anyone help me with this? i ve searched a lot of sites but not found anything to help? my code is below or you can look at my test file @ http://www.shiftyshaun.com/zoom2.zip

      thanks in advance!

      shaun

      import mx.utils.Delegate;
      import flash.geom.Rectangle;
      import flash.geom.Point;
      import mx.transitions.Tween;
      import mx.transitions.easing.*;
      image._x = 0;
      image._y = 0;
      image.cacheAsBitmap = true;
      target = _root;
      rect = new Rectangle(0, 0, 640, 480);
      mouse = new Point(0, 0);
      x_pos = 0;
      y_pos = 0;
      r_img = new Rectangle(0, 0, image._width, image._height);
      r_mask = new Rectangle(image._x, image._y, rect.width, rect.height);
      function start():Void {
      image.scrollRect = rect;
      image.onEnterFrame = Delegate.create(this, enterframe);
      }
      moving = true;
      function enterframe():Void {
      if (moving) {
      mouse.x = target._xmouse;
      mouse.y = target._ymouse;
      if (r_mask.containsPoint(mouse)) {
      y_pos = ((Math.abs(image._y-mouse.y)/rect.height)*(r_img.height-rect.height));
      x_pos = ((Math.abs(image._x-mouse.x)/rect.width)*(r_img.width-rect.width));
      }
      rect.x += (x_pos-rect.x)/8;
      rect.y += (y_pos-rect.y)/8;
      image.scrollRect = rect;
      }
      }
      start();
      var my_event = new Object();
      my_event.target = image;
      Mouse.addListener(my_event);
      my_event.onMouseDown = function() {
      if (moving) {
      moving = false;
      zoomIn();
      } else {
      zoomOut();
      moving = true;
      }
      };
      zoomIn = function () {
      new Tween(image, "_xscale", Strong.easeOut, 100, 150, 1, true);
      new Tween(image, "_yscale", Strong.easeOut, 100, 150, 1, true);
      trace("rect x = "+rect.x+" rect y = "+rect.y);
      };
      zoomOut = function () {
      new Tween(image, "_xscale", Strong.easeOut, 150, 100, 1, true);
      new Tween(image, "_yscale", Strong.easeOut, 150, 100, 1, true);
      trace("rect x = "+rect.x+" rect y = "+rect.y);
      };