0
votes
var txtIt:Text = new Text();
                txtIt.text = full_array[t][0];
                txtIt.width = 700;
                txtIt.buttonMode = true;
                txtIt.mouseChildren = false;
                txtIt.selectable = false;
                txtIt.y = t * 30;

                trace(txtIt.textWidth);

                myCanvas.addChild(txtIt);

Why can't i get the textWidth for the component? I can get it for textFields.

I've used the namespace code and i have this:

 import mx.core.mx_internal;
use namespace mx_internal;

            var txtIt:Text = new Text();



                txtIt.text = full_array[t][0];
                txtIt.width = 700;
                txtIt.buttonMode = true;
                txtIt.mouseChildren = false;
                txtIt.selectable = false;
                txtIt.y = t * 30;

                var txtfld:TextField = txtIt.getTextField() as TextField;
                trace(txtfld.textWidth);


                myCanvas.addChild(txtIt);

But I get TypeError: Error #1009: Cannot access a property or method of a null object reference.

1

1 Answers

1
votes

You need to use the mx_internal namespace so that you can access the TextField object of the Text component. In your ActionScript code you have to declare

import mx.core.mx_internal;
use namespace mx_internal;

and then something like

var myText:Text = new Text();
var txtfld:TextField = myText.getTextField() as TextField;

All the text measuring properties and methods are available through the TextField