Im trying to get the value of the textWidth property in class Main from a text field created in an instantiated class Label. When I trace the value from within the Label class I have access to the values. I’m trying to use a get function to pass the value to the main class. What am i doing wrong.
Thanks in advance!
package
{
import com.greensock.*;
import com.greensock.easing.*;
import flash.text.*;
import flash.display.*;
import flash.events.*;
import flash.text.TextField;
public class Main extends MovieClip{
private var theNav:TheNav;
private var label1:Lable;
private var label2:Lable;
private var label3:Lable;
private var label4:Lable;
public function Main()
{
init();
}
function init(){
theNav = new TheNav();
addChild(theNav);
label1 = new Lable("label1");
label1.x = 100;
label1.y = 0;
label1.mouseEnabled = false;
theNav.addChild(label1);
label2 = new Lable("label2");
label2.x = 200;
label2.y = 0;
label2.mouseEnabled = false;
theNav.addChild(label2);
label3 = new NavLable("label3");
label3.x = 0;
label3.y = 100;
label3.mouseEnabled = false;
theNav.addChild(label3);
label4 = new Lable("label4");
label4.x = 0;
label4.y = 200;
label4.mouseEnabled = false;
theNav.addChild(label4);
trace(label4.getLabelWidth + " = getLabelWidth()"); // //trace statment returns : 0 = theLabelWidth()
}
}
}
package {
import com.greensock.loading.*;
import com.greensock.events.*;
import flash.display.*;
import flash.text.*;
public class Label extends Sprite{
private var theLabel:TextField;
private var _theText:String;
private var txtFmt:TextFormat;
private var loader:SWFLoader;
public var _theLabelWidth:int;
public function Label(theText:String) {
_theText = theText;
theLabel = new TextField();
theLabel.text = _theText;
_theLabelWidth = theLabel.textWidth;
trace(_theLabelWidth+ " = _theLabelWidth");
//trace statment returns :
// 70 = _theLabelWidth
// 82 = _theLabelWidth
// 89 = _theLabelWidth
// 135 = _theLabelWidth
this.addChild(theLabel);
}
public function get getLabelWidth():int {
return _theLabelWidth;
}
}
}