0 Replies Latest reply on Aug 15, 2006 7:18 AM by Newsgroup_User

    scrollRect & tween class

    Level 7
      Hi

      I have a flash project which is basically a table top that you can use your
      mouse to navigate around, I have been using Flash 8's new scrollRect
      function. Below is my code, which works fine. The user uses the mouse to
      scroll around the table top, however I want to have menu buttons which will
      take the user directly to an area on the table, but I m confused as to how
      to use the tween class with the scrollRect. My code for scrolling is below:

      Stage.scaleMode = "exactFit";
      // import classes
      import mx.utils.Delegate;
      import flash.geom.Rectangle;
      import flash.geom.Point;
      // constants
      mcMain._x = 0;
      mcMain._y = 0;
      X = (mcMain._width)-(Stage.width/2);
      Y = (mcMain._height)-(Stage.height/2);
      x_pos = X;
      y_pos = Y;
      mcMain.cacheAsBitmap = true;
      target = _root;
      rectWidth = Stage.width;
      rectHeight = Stage.height-mcMenu._height;
      rect = new Rectangle(0, 0, rectWidth, rectHeight);
      mouse = new Point(0, 0);
      r_img = new Rectangle(0, 0, mcMain._width, mcMain._height);
      r_mask = new Rectangle(mcMain._x, mcMain._y, rect.width, rect.height);
      //
      function init():Void {
      rect.x = 333;
      rect.y = 283;
      mcMain.scrollRect = rect;
      }
      startMovement = function ():Void {
      mcMain.onEnterFrame = Delegate.create(this, enterframe);
      };
      function enterframe():Void {
      mouse.x = target._xmouse;
      mouse.y = target._ymouse;
      if (r_mask.containsPoint(mouse)) {
      y_pos =
      ((Math.abs(mcMain._y-mouse.y)/rect.height)*(r_img.height-rect.height));
      x_pos =
      ((Math.abs(mcMain._x-mouse.x)/rect.width)*(r_img.width-rect.width));
      }
      rect.x += (x_pos-rect.x)/9;
      rect.y += (y_pos-rect.y)/9;
      mcMain.scrollRect = rect;
      }
      btn.onPress = function() {
      btn._visible=false;
      startMovement();
      };
      init();

      I have started the following code for the button which takes you to a
      specific area:

      movementSpeed = 2;
      movementEase = Strong.easeOut;
      //
      btn.onPress = function () {
      var moveItX:Tween = new Tween(Object.main.mcMain, "_x", movementEase,
      mcMain._x, 100, movementSpeed, true);
      var moveIt:YTween = new Tween(Object.main.mcBase, "_y", movementEase,
      mcMain._x, 200, movementSpeed, true);

      moveItX.onMotionChanged = function() {
      x_pos = moveIt.position;
      rect.x += (x_pos-rect.x)/9;
      rect.y += (y_pos-rect.y)/9;
      mcMain.scrollRect = rect;
      };
      };

      but this is where i m stuck, does anyone have any idea of how to use tweens
      and the scrollrect?

      any help is appreciated!

      thanks in advance

      Shaun