• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 925
  • Last Modified:

Easy Flash Menu highlight script.

I am working on a flash site and I have a menu with a slightly trnasparent rectangle the is on the top layer. I want to animate the rectangle with actionscript to scroll over an item that is clicked. I want it to animate using actionscript and have some easy on it so the rectanlge will always reach its target in the same amount of frames. For example if its over the first item and someone clicks the last item it will go faster than if someone chooses an item thats next to the one currently selected.

Thanks in advance,
Max
0
TheMaximumWeasel
Asked:
TheMaximumWeasel
  • 2
2 Solutions
 
Jakob_ECommented:
Hi Max

Try this example:
// On your stage:
// Add five buttons on the stage (button1_mc,button2._mc,...)
// Add the rectangle on the stage (marker_mc)

button1_mc.onRelease=function(){markerSlide(this);}
button2_mc.onRelease=function(){markerSlide(this);}
button3_mc.onRelease=function(){markerSlide(this);}
button4_mc.onRelease=function(){markerSlide(this);}
button5_mc.onRelease=function(){markerSlide(this);}

function markerSlide(button){
  // The number of frames
  var frames=10
  // Calculate distance to move per frame
  var distance=(marker_mc._x-button._x)/frames
  // onEnterFrame will execute using the frame rate
  // of your movie as interval
  marker_mc.onEnterFrame=function(){
    // Move marker_mc
    marker_mc._x-=distance;
    // Decrease frames by one
    frames--;
    // If frames is zero the marker has reached its destination
    // and we delete the onEnterFrame execution (a new will be
    // created when a button is clicked)
    if(!frames) delete this.onEnterFrame;
  };
}

Best,
Jakob E
0
 
Jakob_ECommented:
// The slide function in a bit more compressed version :)
function markerSlide(b) {
  var f=10,d=(marker_mc._x-b._x)/f;
  marker_mc.onEnterFrame=function(){marker_mc._x-=d;f--;if(!f)delete this.onEnterFrame;};
}

~ Jakob E
0
 
TheMaximumWeaselAuthor Commented:
I figured it out thanks anyway
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now