1 Reply Latest reply on Feb 1, 2007 6:28 AM by Jan-Paul K.

    slide accrondign to mouse

    pablo scillia
      hi
      im trying to modify a .fla flife that i found
      and it consist in move the background based on the mouse movement
      this sample i got is only moving at _x position (horizontal)
      and i want to make it only for _y (vertical)
      i try to modify the script but im not so good on that
      can anyone help me modifing it?

      here it is:

      quote:

      fscommand("fullscreen", "true");
      Stage.scaleMode = "noScale";
      //Center the stage elements
      var myListener:Object = new Object();
      myListener.onResize = function() {
      updateLocations();
      };
      Stage.addListener(myListener);
      updateLocations = function () {
      // Values of the initial .swf width and height
      initialWidth = 800;
      initialHeight = 450;
      // Get the current stage width and height
      currentWidth = Stage.width;
      currentHeight = Stage.height;
      // Get the content width
      contentWidth = contentClip._width;
      // Position content vertically
      contentClip._y = Math.round((initialHeight/2)-(contentClip._height/2));
      // Center the content if the content width is less than currentWidth
      if (contentClip._width<currentWidth) {
      newX = Math.round(initialWidth/2-contentClip._width/2);
      } else {
      positionContent();
      newX = Math.round(initialWidth/2-contentClip._width/2);
      }
      };
      updateLocations();



      quote:

      //Number of buffer pixels to add on each side of the content
      buffer = 0;
      //Scroll the content relative to the mouse
      this.onMouseMove = function() {
      //Only fire if mouse is over the content area
      if ((this._xmouse>Math.floor((initialWidth-currentWidth)/2)) && (this._xmouse<Math.floor(initialWidth+2*((currentWidth-initialWidth)/2))) && (this._ymouse>contentClip._y) && (this._ymouse<(contentClip._y+contentClip._height))) {
      //Make sure the content width is larger than the currentWidth
      if (contentClip._width>currentWidth) {
      positionContent();
      }
      }
      };
      positionContent = function () {
      // Percent of mouse position on content
      mousePercent = (this._xmouse+(currentWidth-initialWidth)/2)/currentWidth;
      // Total available movement of the content minus screen width
      availMovement = contentClip._width-currentWidth+buffer*2;
      newX = Math.floor(-mousePercent*availMovement)-(currentWidth-initialWidth)/2+(buffer*2)/2;
      };
      //Set the initial position to the left side of the screen if content width is more than currentWidth, else center the content
      if (contentClip._width>currentWidth) {
      newX = Math.floor((initialWidth-currentWidth)/2)+buffer;
      } else {
      //Center the content
      newX = Math.floor(initialWidth/2-contentClip._width/2);
      }
      //The following 2 functions can be rewritten to utilize the Braingiants Bounce function for improved recycling (it is presented as is for clarity of the actual movement)
      holder = contentClip._x;
      easeContent = function () {
      // Don't fire if the destination position is met
      if (newX<>contentClip._x) {
      destx = newX;
      posx = holder;
      velx = (destx-posx)/4;
      holder += velx;
      contentClip._x = Math.round(holder);
      }
      };
      contentClip.onEnterFrame = function() {
      easeContent();
      };
      updateLocations();
      stop();


        • 1. Re: slide accrondign to mouse
          Jan-Paul K.
          did you even try to change the script on your own? or did you try to understand how the script works?

          If you just posted the script here to let others do the work for you, you will never learn how to code in actionscript.

          Just a tip: the main efforts to be done is in the "this.onMouseMove"-Event handler part and the positionContent function. The first script most likely does not need to be touched at all.

          If you have any specific questions, don't hesitate to ask.