A TextField called Dolly
I love Flash IDE. Especially the way you can stylise the TextField
– decide what glyphs to embed and what fonts to include, set line height (leading), kerning (letterSpacing), colours, etc. I really hate creating new TextFields from scratch, entirely in code.
Using Library to store a TextField
Unfortunately, we can't store a TextField
directly as a Flash IDE library symbol, so we have to wrap it up in a MovieClip
and reference to it as follows:
var textFieldNormal:TextField = new TextMC().textTF;
where TextMC
is the library MovieClip symbol containing a TextField
named textTF
.
How to duplicate (clone) a TextField?
You can't do it natively in AS3. But you can do some magic instead – clone all (excluding read-only) properties of another TextField.
var description:XML = describeType(referenceTextField); for each (var item:XML in description.accessor) { // clone passed textfield properties that are not read only if (item.@access != "readonly") targetTextField[item.@name] = referenceTextField[item.@name]; } targetTextField.defaultTextFormat = referenceTextField.getTextFormat();
TextFormat
of the referenceTextField
won't be cloned with the loop above as it's not accessible via getter/setter/public methods. You have to clone it manually and this is what the last line does. It's very handy when you want to change the default kerning (letterSpacing
) in Flash IDE and you want it to be preserved in your cloned text field.
I wrote a FixedTextField class that does that (plus fixes a couple of other TextField problems) – download zipped demo including the class.
01:00 PM | posts | 0 Comments | Tags: textfield, flash ide, as3, tips, source, debuggingComments
Adding comments disabled for now.