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.addEventList
ener(Event
.COMPLETE,
menuXMLLoaded);
var menuXML:XML;
var p:int = 0;
function menuXMLLoaded(event:Event)
:void {
menuXmlLoader.removeEventL
istener(Ev
ent.COMPLE
TE, 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.descripti
on[p];//fi
lls 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:TextForm
at = new TextFormat();
menuBoxTextFormat.font = "Helvetica";
menuBoxTextFormat.size = 12;
menuBoxTextFormat.color = 0xFFFFFF;
menuBoxText.setTextFormat(
menuBoxTex
tFormat);
//here's a semi-transparent background for the panel
var menuBoxRect:Shape = new Shape();
menuBoxRect.graphics.begin
Fill(0x555
448, .74);
menuBoxRect.graphics.drawR
ect(0, 0, 372, 426);
menuBoxRect.graphics.endFi
ll();
menuBoxRect.height = menuBoxText_height + 35;//here's a place i try to use the var
//here I put the current pieces together
menuBox.addChild(menuBoxRe
ct);
menuBox.addChild(menuBoxTe
xt);
addChild(menuBox);
trace(menuBoxText_height);
}