1 Reply Latest reply on Mar 31, 2007 7:57 AM by abeall

    I'm trying to use _alpha with the _xmouse to interactively fade a box with the mouse pointer.

    niic
      Hi guys,

      I’m new to Flash sort of but most definitely new to actionscript and programming in general. I’m hoping someone can help me with a practice thing I’ve been working on - I thought this would be easy to start of with but it is prooving very challenging;

      I’m trying to create an image fade on a box when the mouse is within its borders. Essentially I want to get 0% _alpha on the left edge of the box and 100% on the right edge and dragging the mouse over the box in the x coord will interactively raise or lower the _alpha %.

      --see attached code for details--
      red_mc is the name of my red box which is 123pixels center of my stage which is 550. When I first started this it was from an online tutorial but it was for the entire stage hence my division by 550 pixels in the changeAlpha function. I need help trying to control the return values for _xmouse within my box to control the _alpha property.

      Any help would be great. Thanks!

      Regards,
      Nick.
        • 1. Re: I'm trying to use _alpha with the _xmouse to interactively fade a box with the mouse pointer.
          abeall Level 3
          1) Use getBounds() to determine the actual coordinates the box takes up. If the box's registration is not in it's upper left or left, other methods could be flaky.

          2) Find the difference between getBounds().xMin and _xmouse

          3) Find the percent(from 0 to 1) of the box's width that difference is(say, a little under half way from left to right, or .45)

          3) Multiple times 100 and that's the alpha

          Here:
          red_mc.onRollOver = function() {
          mouseInterval = setInterval(changeAlpha,10,red_mc);
          }
          red_mc.onRollOut = red_mc.onReleaseOutside = function() {
          clearInterval(mouseInterval);
          }

          function changeAlpha (mc) {
          // pass in the MovieClip as an argument, so it's more flexible
          var bounds = mc.getBounds(_root); // find target mc's bounds on _root
          var xDif = _root._xmouse-bounds.xMin; // determine how far from mc's left bound the mouse is
          var percent = xDif/mc._width; // determine what percentage of the mc the mouse is at
          mc._alpha = 100*percent; // max alpha times percent gives desired alpha
          trace(mc._alpha);
          updateAfterEvent(); // this forces Flash to redraw, independent of frame rate
          }

          Hope that helps