[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

How do I return the resized height of an XML loaded dynamic text field in ActionScript 3.0?

Asked by cowboyX in Adobe Flash, ActionScript

Tags: as3, ActionScript 3.0, xml, dynamic TextField

Hello. I'm making an accordion menu whose panels are text from an external xml file. The height of each panel will need to correspond to the amount of text in that panel.

When I started to construct the panel I came across a problem.  When I run the code below, the trace returns a value of 4 no matter how much text is in the xml, even though all of the text is visible.  I need to know how I can find the true height of the text field once it is filled with the text from the xml file, so that I can use that value to adjust the height of the panel, pass it to a scrollbar, etc.

Here is the code.  Thanks for any help.

import cowboyX.LoadXml; //this is a simple xml parsing class

var menuXmlLoader:LoadXml = new LoadXml("aboutMenu.xml");
menuXmlLoader.addEventListener(Event.COMPLETE, menuXMLLoaded);

var menuXML:XML;
var p:int = 0;

function menuXMLLoaded(event:Event):void {
      menuXmlLoader.removeEventListener(Event.COMPLETE, menuXMLLoaded);
      menuXML = menuXmlLoader.loadedXML;
      loadMenu();
}
//here's the part that makes the panel
function loadMenu():void {
      var menuBox:MovieClip = new MovieClip();

      //this is the dynamic text field
      var menuBoxText:TextField = new TextField();
      menuBoxText.autoSize = TextFieldAutoSize.LEFT;
      menuBoxText.wordWrap = true;//this and the above line autosize the text field's height
      menuBoxText.type = TextFieldType.DYNAMIC;
      menuBoxText.embedFonts = true;
      menuBoxText.mouseEnabled = false;
      menuBoxText.x = 20;
      menuBoxText.y = 25;
      menuBoxText.width = 332;
      menuBoxText.htmlText = menuXML.menuitem.description[p];//fills the field with the xml

      //here is the var I want to utilize further
      var menuBoxText_height:Number = menuBoxText.height;

      //here's formatting for the text
      var menuBoxTextFormat:TextFormat = new TextFormat();
      menuBoxTextFormat.font = "Helvetica";
      menuBoxTextFormat.size = 12;
      menuBoxTextFormat.color = 0xFFFFFF;
      menuBoxText.setTextFormat(menuBoxTextFormat);

      //here's a semi-transparent background for the panel
      var menuBoxRect:Shape = new Shape();
      menuBoxRect.graphics.beginFill(0x555448, .74);
      menuBoxRect.graphics.drawRect(0, 0, 372, 426);
      menuBoxRect.graphics.endFill();
      menuBoxRect.height = menuBoxText_height + 35;//here's a place i try to use the var

      //here I put the current pieces together
      menuBox.addChild(menuBoxRect);
      menuBox.addChild(menuBoxText);
      addChild(menuBox);
      trace(menuBoxText_height);
}
[+][-]11/06/09 02:15 AM, ID: 25757904Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 04:59 AM, ID: 25758686Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 05:06 AM, ID: 25758722Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 07:09 AM, ID: 25759728Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 07:11 AM, ID: 25759755Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 07:48 AM, ID: 25760104Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625