[Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

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; inode_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, 

RE: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Merrill, Jason
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; inode_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

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

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: 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; inode_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

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

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; inode_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

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

Elena,

Option 2 is exactly the track I am currently taking!

I am having a hard time adjusting the width of the movie clip based on
the length of the text after setting it to auto size. Can you help?

Here is my code:

for (var i=0; inode_xml.childNodes.length; i++) {
// movieclip for each menu item
curr_item = curr_menu.attachMovie(menuitem,item+i+_mc, i);
curr_item.name.autoSize = left;
curr_item._width = curr_item.name.textWidth;
curr_item._x = x + i*curr_item._width;
curr_item._y = y;
curr_item.trackAsMenu = true;
// truncated

Thanks,
Aaron

P.S. Option #2 is:

quoteYou could set autosize = true for the dynamic text field, then retrieve
the length of the text field once populated with the text, the adjust the
width of the movie clip based on it.. all on the fly./quote


On 8/17/06, Elena Blanco [EMAIL PROTECTED] wrote:

A couple of ideas that pop in my mind

1. You can store the name in a temporary string and get the length of it
with string.length - then change the width of the movie clip accordingly
2. You could set autosize = true for the dynamic text field, then retrieve
the length of the text field once populated with the text, the adjust the
width of the movie clip based on it.. all on the fly.

Let me know if any helps!

ELENA BLANCO
Blancomedia
WEB APPLICATION ARCHITECT
920 HULL STREET
HOOD RIVER, OR 97031
p: 541.490.4993
e: [EMAIL PROTECTED]
w: http://www.blancomedia.com


-Original Message-
From: Aaron Roberson [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 17, 2006 2:13 PM
To: [EMAIL PROTECTED]
Subject: Re: [Flashcoders] Help Getting Size of Text Dynamically

Yes, I am referring to the length of the text in the name attribute of
the xml nodes.

The script is creating a new movie clip based on an existing movie
clip in the library. The movie clip in the library (menuitem) has an a
movie clip (arrow) and a dynamic text field (name). When the script
creates the new movie clips for each menu item, instead of making them
the width of the text, they are the width of the movie clip in the
library. The width of the movie clip in the library is based on the
text inside, which makes me think that I could change the width of the
generated movie clips based on the text loaded from xml.

I hope that makes sense!

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: 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; inode_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

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

Elena,

Option 2 is exactly the track I am currently taking!

I am having a hard time adjusting the width of the movie clip based on
the length of the text after setting it to auto size. Can you help?

Here is my code:

for (var i=0; inode_xml.childNodes.length; i++) {
// movieclip for each menu item
curr_item = curr_menu.attachMovie(menuitem,item+i+_mc, i);
curr_item.name.autoSize = left;
curr_item._width = curr_item.name.textWidth;
curr_item._x = x + i*curr_item._width;
curr_item._y = y;
curr_item.trackAsMenu = true;
// truncated

Thanks,
Aaron

P.S. Option #2 is:

quoteYou could set autosize = true for the dynamic text field, then retrieve
the length of the text field once populated with the text, the adjust the
width of the movie clip based on it.. all on the fly./quote

On 8/17/06, Elena Blanco [EMAIL PROTECTED] wrote:

A couple of ideas that pop in my mind

1. You can store the name in a temporary string and get the length of it
with string.length - then change the width of the movie clip accordingly
2. You could set autosize = true for the dynamic text field, then retrieve
the length of the text field once populated with the text, the adjust the
width of the movie clip based on it.. all on the fly.

Let me know if any helps!

ELENA BLANCO
Blancomedia
WEB APPLICATION ARCHITECT
920 HULL STREET
HOOD RIVER, OR 97031
p: 541.490.4993
e: [EMAIL PROTECTED]
w: http://www.blancomedia.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


Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread John VanHorn

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: 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; inode_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

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

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; inode_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: 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; inode_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

RE: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Ryan Potter
Hey Aaron.  The problem that I can see is that you are setting the x to
the x of the current item, hence you are setting it to its own width.
If you are trying to space them across the screen horizontally you need
to get the x and width of the last clip.  Another way to do it is to get
the width of the container clip and use that.  This only works if the
container only contains the nav items.  

Option 1:

// get the last clip (i-1)
last_item = curr_menu[item+i-1+_mc];
last_x = last_item._x;
last_width = ast_item._width;

// set the x to the last item x plus the last item width
curr_item._x = last_x + last_width;


Option 2:
// set the x to the width of the container
curr_item._x = curr_menu._width;


Option 3:

// Set a fixed width
curr_item._x = i*100;


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Aaron
Roberson
Sent: Thursday, August 17, 2006 4:23 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Help Getting Size of Text Dynamically

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; inode_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: 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; inode_xml.childNodes.length; i++) {
   // movieclip for each menu item
   curr_item =
  curr_menu.attachMovie(menuitem,item+i+_mc,
   i

Re: [Flashcoders] Help Getting Size of Text Dynamically

2006-08-17 Thread Aaron Roberson

Ryan,

I went with option number 1 and it is working like a champ. I did
change one little thing:

last_item = curr_menu[item+i-1+_mc];

to

last_item = curr_menu[item+(i-1)+_mc];

But it works wonderfully now. Thank you all for your help!

-Aaron

On 8/17/06, Ryan Potter [EMAIL PROTECTED] wrote:

Hey Aaron.  The problem that I can see is that you are setting the x to
the x of the current item, hence you are setting it to its own width.
If you are trying to space them across the screen horizontally you need
to get the x and width of the last clip.  Another way to do it is to get
the width of the container clip and use that.  This only works if the
container only contains the nav items.

Option 1:

// get the last clip (i-1)
last_item = curr_menu[item+i-1+_mc];
last_x = last_item._x;
last_width = ast_item._width;

// set the x to the last item x plus the last item width
curr_item._x = last_x + last_width;


Option 2:
// set the x to the width of the container
curr_item._x = curr_menu._width;


Option 3:

// Set a fixed width
curr_item._x = i*100;


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Aaron
Roberson
Sent: Thursday, August 17, 2006 4:23 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Help Getting Size of Text Dynamically

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; inode_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: 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