A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Images and text on button rollovers

  1. #1
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Images and text on button rollovers

    I've created a main menu with 9 button movie clips, all from the same library button. When the user rolls over the buttons on the left of the screen I would like a graphic and some text to appear on the right side of the screen.

    Can I put the 9 different images links and text into an array and read it on the fly during the rollover? I'm looking at that but in the button editor I don't see how I can put a dynamic image and text on the screen.

    Any suggestions on the best way to do this?

    Thanks
    RonM

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    you need to do it in actionscript, heres how you can do it (based on your requirement description):

    Code:
    //for each button on the stage, give them a class name, eg: Button1
    
    //give each button an instance name and place them in array
    var buttons:Array - new Array(button1, button2, button3, etc);
    
    //loops though the buttons giving eventlistener for function showItems and hideItems
    foreach(var button in buttons) {
         button.addEventListener(MouseEvent.ROLL_OVER, showItems);
         button.addEventListener(MouseEvent.ROLL_OUT, hideItems);
    
    }
    
    //the easy way to display the items on the right is to make a movieclip
    //for each item containing the image and text
    //place each item movieclip on top of eachother where you want them to appear
    //and set each of their alpha properties to 0
    //dont forget to give them the relative instance names: item1, item2, item 3 etc
    
    //for each button create a new property called targeter
    //and attach the relative item to each one
    button1.targeter = item1;
    button2.targeter = item2;
    button3.targeter = item3;
    //etc for all 9
    
    function showItems(e:MouseEvent):void {
         e.currentTarget.targeter.alpha = 1;
    }
    
    function hideItems(e:MouseEvent):void {
         e.currentTarget.targeter.alpha = 0;
    }
    that SHOULD do what you wanted to do, tell me if you have any trouble.

    flos
    Last edited by flosculus; 08-22-2009 at 12:42 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center