Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / March 2007



Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
niic - 31 Mar 2007 12:36 GMT
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.

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

function changeAlpha () {
    red_mc._alpha = Math.round(_root._xmouse/550*100);
    trace(red_mc._alpha);
};
abeall - 31 Mar 2007 15:57 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.