A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: dynamic menu horizontal layout

  1. #1
    Senior Member
    Join Date
    May 2000
    Posts
    814

    dynamic menu horizontal layout

    I think this could be simple!!

    XML feed to my horizontal menu, i can measure the text width ok, but i can't figure out the algebra on how to layout my menu text side by side with a 20 pixel gap.

    PHP Code:
    function createMyMenu():void {


        
    //This will be used to represent a menu item
        
    var menuItem:MenuItem;
        
        
    //Counter
        
    var i:uint 0;
        var 
    w:Number;
        var 
    s:Number;
        


            
    //Loop through the links found in the XML file
            
    for each (var link:XML in xml.link) {

            
    menuItem = new MenuItem();
            
    menuItem.id i;

            
    //If the text is longer than the textfield, autosize so that the text is 
            //treated as left-justified text
            
    menuItem.menuLabel.autoSize TextFieldAutoSize.LEFT;

            
    //Insert the menu text (link.@pgTitle reads the link's "pgTitle" attribute)
            
    menuItem.menuLabel.text link.@pgTitle;

            
    menuItem.0;
            
    menuItem.menuLabel.width;
            
    20;
            
            
    //// this is wrong /////   
                    
    menuItem.i* (s);
                    
    //// i cant work it out ///// 

    trace("width"w);


            
    //Make the button look like a button (hand cursor)
            
    menuItem.buttonMode true;
            
    menuItem.mouseChildren false;
            
            
    //Add event handlers (used for animating the buttons)
            
    menuItem.addEventListener (MouseEvent.MOUSE_OVERmouseOverHandler);
            
    menuItem.addEventListener (MouseEvent.MOUSE_OUTmouseOutHandler);
            
    menuItem.addEventListener (MouseEvent.MOUSE_DOWNmousePressHandler);

            
    menuMC.addChild(menuItem);
            

            
    //Increment the menu button counter, so we know how many buttons there are
            
    i++;
            
            
        }



  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    921
    menuItem.x = i* (w + s); << this would only work if w is the same for every label. otherwise you need to store last_item_x_plus_w and do menuItem.x = last_item_x_plus_w + s;
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    Senior Member
    Join Date
    May 2000
    Posts
    814
    yes i understand the logic, but i'm not sure about how to script it.

    do i need to make a array for the width values?

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