Jump to content
Search Community

TweenMax with TLF properties?

Z0OTY test
Moderator Tag

Recommended Posts

Is it possible to tween properties of TLF textfields? Say I want to tween the tracking of a TLF textfield, How would I go about doing that? I tried giving an instance name to the TLF field and tweening the "tracking" property, but it returned a reference error # 1069 property not found.

 

Any suggestions?

Link to comment
Share on other sites

Sure, you can tween almost any property but some objects in Flash require a little extra elbow grease. TLFTextFields don't have a "tracking" property, so you can't just tween that. To apply formatting to text in a TLFTextField, you must use a TextFormat object and pass it to the setTextFormat() method of the TLFTextField. Yeah, doesn't exactly feel intuitive but you can thank Adobe for that.

 

Oh, and TextFormat has a "letterSpacing" property, not "tracking".

 

You'd just tween the TextFormat's properties and then use an onUpdate to apply it to the TLFTextField each time the value gets updated. Here's an example that you can copy/paste into an FLA:

 

import fl.text.TLFTextField;
import flash.text.*;
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([HexColorsPlugin]); //activate this plugin so that we can tween colors

var tlf:TLFTextField = new TLFTextField();
tlf.text = "tween letterSpacing";
tlf.width = 800;
var format:TextFormat = tlf.getTextFormat(0); //this is what we'll actually tween - the format.
addChild(tlf);

TweenLite.to(format, 5, {letterSpacing:20, size:30, hexColors:{color:0xFF0000}, onUpdate:applyFormat});
function applyFormat():void {
tlf.setTextFormat(format);
}

 

That will tween not only the letterSpacing but also the size and the color! Okay, I got a little fancy with that color stuff, but I wanted you to see how you can animate just about anything - it's just a matter of using the right tools and applying the values according to the way Flash requires it.

 

In case it helps, here's a link to Adobe's docs on TextFormat:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextFormat.html

 

And for TLFTextField:

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/fl/text/TLFTextField.html#setTextFormat%28%29

 

Does that clear things up?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...