Easy Flash Menu highlight script.

Posted on 2007-08-04
Last Modified: 2013-11-05
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,
Question by:TheMaximumWeasel
    LVL 9

    Accepted Solution

    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)


    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
        // Move marker_mc
        // Decrease frames by one
        // 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;

    Jakob E
    LVL 9

    Assisted Solution

    // 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
    LVL 4

    Author Comment

    I figured it out thanks anyway

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Read about why website design really matters in today's demanding market.
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now