John,

That is what I am trying to do but it's not working for some reason.
Can you detect any problem or give me a suggestion with the following
code:

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);
              //set text field to auto size with left alignment
              curr_item.name.autoSize = "left";
              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;

              // set movie clip width to the width of the text loaded from xml
              curr_item._width = curr_item.name.textWidth;
              // set x coordinate to the coordinate passed in times
the width of the movie clip
              curr_item._x = x + i*curr_item._width;
              curr_item._y = y;

Thanks,
Aaron

On 8/17/06, John VanHorn <[EMAIL PROTECTED]> wrote:
there are many ways to do the spacing. if your mc is sized after the width
of the textfield, just add the witdh of the mc to its _x plus the 15px for
spacing to get the _x of the next mc.

On 8/17/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
>
> I'm half way there...
>
> I figured out how to resize the movie clip based on the length of the
> text being loaded from the name attribute of the xml node. I added the
> following line to my code:
>
> curr_item.name.autoSize = "left";
>
> Now I need to figure out how to make the spacing between each menu
> item 15px. Sounds simple, and is for others, but now that each movie
> clip is a different size I'm not sure how to do that. Any help on that
> would be appreciated!
>
> -Aaron
>
> On 8/17/06, Elena Blanco <[EMAIL PROTECTED]> wrote:
> > By size, are you referring to the length of the text (in this case the
> > name?)
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Aaron
> > Roberson
> > Sent: Thursday, August 17, 2006 1:55 PM
> > To: [email protected]
> > 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");
> > _______________________________________________
> > [email protected]
> > 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
> >
> >
> _______________________________________________
> [email protected]
> 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
>



--
John Van Horn
[EMAIL PROTECTED]
_______________________________________________
[email protected]
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

_______________________________________________
[email protected]
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