Jason,

I used textfield.autoSize = "left" which seems to fix half of my
problem. Maybe I can use textfield.textWidth to fix the other half -
which is to get the menu items to be evenly spaced from one another
and not spaced on a static value.

I post back...

Aaron

P.S. That textfield is "name".

On 8/17/06, Merrill, Jason <[EMAIL PROTECTED]> wrote:
XML is actually not relevant to the question here.  Only the text string
you get from it is.  Once the text string is in a TextField, you should
just be able to use the TextField.textWidth property.

Jason Merrill
Bank of America
Learning & Organization Effectiveness - Technology Solutions






>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:flashcoders-
>>[EMAIL PROTECTED] On Behalf Of Aaron Roberson
>>Sent: Thursday, August 17, 2006 4:55 PM
>>To: flashcoders@chattyfig.figleaf.com
>>Subject: [Flashcoders] Help Getting Size of Text Dynamically
>>
>>I am creating a dynamic drop down menu using XML and I am having
>>trouble spacing out each menu item.
>>
>>Is there a way of determing the size of the text in each xml node?
>>
>>Thanks for your help,
>>Aaron
>>
>>P.S. This menu is based on a tutorial at kirupa.com.
>>
>>Here is the XML:
>>
>><?xml version="1.0" encoding="iso-8859-1"?>
>><menu name="navigation">
>>      <item name="Home" link="http://whitehorsemedia.com"; />
>>      <menu name="About Us"
>>link="http://whitehorsemedia.com/about/index.cfm";>
>>              <item name="Our Name"
>>link="http://whitehorsemedia.com/about/name.cfm"; />
>>              <item name="News"
>>link="http://whitehorsemedia.com/about/news.cfm"; />
>>              <item name="We Believe"
>>link="http://whitehorsemedia.com/about/believe.cfm"; />
>>              <item name="Staff"
>>link="http://whitehorsemedia.com/about/staff.cfm"; />
>>              <item name="Projects"
>>link="http://whitehorsemedia.com/about/projects.cfm"; />
>>      </menu>
>></menu>
>>
>>Here is the ActionScript:
>>
>>
>>// generates a list of menu items (effectively one menu)
>>// given the inputted parameters.  This makes the main menu
>>// as well as any of the submenus
>>GenerateMenu = function(container, name, x, y, depth, node_xml) {
>>      // variable declarations
>>      var curr_node;
>>      var curr_item;
>>      var curr_menu = container.createEmptyMovieClip(name, depth);
>>
>>      // for all items or XML nodes (items and menus)
>>      // within this node_xml passed for this menu
>>      for (var i=0; i<node_xml.childNodes.length; i++) {
>>              // movieclip for each menu item
>>              curr_item =
curr_menu.attachMovie("menuitem","item"+i+"_mc",
>>i);
>>              curr_item._x = x + i*curr_item._width;
>>              curr_item._y = y;
>>              curr_item.trackAsMenu = true;
>>
>>              // item properties assigned from XML
>>              curr_node = node_xml.childNodes[i];
>>              curr_item.link = curr_node.attributes.link;
>>              curr_item.name.text = curr_node.attributes.name;
>>
>>              // item submenu behavior for rollover event
>>              if (node_xml.childNodes[i].nodeName == "menu"){
>>                      // open a submenu
>>                      curr_item.node_xml = curr_node;
>>                      curr_item.onRollOver = curr_item.onDragOver =
>>function(){
>>                              var x = 200;
>>                              var y = this._y + this._height;
>>                              GenerateMenu(curr_menu, "submenu_mc", x,
y,
>>1000, this.node_xml);
>>                              // show a hover color
>>                              var col = new Color(this.background);
>>                              col.setRGB(0xf4faff);
>>                      };
>>              }else{ // nodeName == "item"
>>                      curr_item.arrow._visible = false;
>>                      // close existing submenu
>>                      curr_item.onRollOver = curr_item.onDragOver =
>>function(){
>>                              curr_menu.submenu_mc.removeMovieClip();
>>                              // show a hover color
>>                              var col = new Color(this.background);
>>                              col.setRGB(0xf4faff);
>>                      };
>>              }
>>
>>              curr_item.onRollOut = curr_item.onDragOut = function(){
>>                      // restore color
>>                      var col = new Color(this.background);
>>
col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
>>              };
>>
>>              // any item, menu opening or not can have actions
>>              curr_item.onRelease = function(){
>>                      Actions["goToURL"](this.link);
>>                      CloseSubmenus();
>>              };
>>      } // end for loop
>>};
>>
>>// create the main menu, this will be constantly visible
>>CreateMainMenu = function(x, y, depth, menu_xml){
>>      // generate a menu list
>>      GenerateMenu(this, "mainmenu_mc", x, y, depth,
menu_xml.firstChild);
>>      // close only submenus if visible durring a mouseup
>>      // this main menu (mainmenu_mc) will remain
>>      mainmenu_mc.onMouseUp = function(){
>>              if (mainmenu_mc.submenu_mc &&
>>!mainmenu_mc.hitTest(_root._xmouse,
>>_root._ymouse, true)){
>>                      CloseSubmenus();
>>              }
>>      };
>>};
>>
>>// closes all submenus by removing the submenu_mc
>>// in the main menu (if it exists)
>>CloseSubmenus = function(){
>>      mainmenu_mc.submenu_mc.removeMovieClip();
>>};
>>
>>// This actions object handles methods for actions
>>// defined by the XML called when a menu item is pressed
>>Actions = Object();
>>Actions.gotoURL = function(urlVar){
>>      getURL(urlVar, "_blank");
>>};
>>
>>// load XML, when done, run CreateMainMenu to interpret it
>>menu_xml = new XML();
>>menu_xml.ignoreWhite = true;
>>menu_xml.onLoad = function(ok){
>>      // create main menu after successful loading of XML
>>      if (ok){
>>              CreateMainMenu(200, 250, 0, this);
>>      }
>>};
>>// load first XML menu
>>menu_xml.load("menu.xml");
>>_______________________________________________
>>Flashcoders@chattyfig.figleaf.com
>>To change your subscription options or search the archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training
>>http://www.figleaf.com
>>http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to