Aniamting Text with TweenLite
Learn how to animate text using the TweenLite Library.
Video Transcript
00:00All right.
00:00So if there's no more questions, what
00:02I want to do with the time that we have left
00:04is to go back to our planned chapter two.
00:08And I'm going to try to find something interesting
00:11in this chapter two area.
00:13And I'm going to show you another way
00:18of creating animations.
00:20So the traditional way of creating animations,
00:22you've seen the basics of animations.
00:25I want to show you also one more thing
00:27that you can do with these type of animations
00:29is that you don't have to animate only visual elements.
00:34You can really animate anything that is text-wise.
00:37So for example, I want to create an animation of my text
00:40this time around.
00:41And I already pre-populated some text here.
00:44Oops, cancel.
00:47What am I doing here?
00:49OK.
00:49So I already pre-populated some copy here.
00:52And what I want to do is I want to get this copy inside
00:54of my text field.
00:56And by the way, there's a lot more
00:57to talk about activate.
01:00Let me just say really quickly that once you activate
01:04a plugin, you don't have to activate it again.
01:07So if you've activated it in any class,
01:09then it activates it already.
01:12You don't need to.
01:13You could if you want to, but it doesn't really do anything.
01:16Speaking of which, if you use the tween max library even
01:19once, you don't need to use the tween line anymore
01:22because it automatically activated all the files
01:25and already loaded up your files on your flash side.
01:29So there's no point in using tween line anymore.
01:32So if you use tween max, just use tween max all the time.
01:35If you're using tween line, use tween line all the time.
01:38If you're using tween line, this
01:39is that option of activating all the stuff that you're using,
01:42making sure that you're not going to use up file sizes
01:44that you don't need.
01:45What you're using with the tween max, what it's doing,
01:47it's pre-loading a lot of stuff that you probably
01:49are never going to use or rarely are going to use.
01:52And then you're just going to add file size to your project
01:54that you don't really need.
01:55In general, I suggest always use the tween line
01:57and just know what tween max has in case
01:59you ever need to use it.
02:01There isn't really that much stuff in tween max
02:03that you can't do with tween line.
02:04Most of the stuff you could do in tween max,
02:06you could do with tween line.
02:07There's a really small set of stuff
02:08that are explicitly only tween max.
02:11So enough about that.
02:12I want to start animating.
02:13It's been too long.
02:14So I'm going to go with my text here.
02:16And I'm just going to, what I really want to do
02:18is I'm going to go to my team names.
02:20I'm going to go to my text here.
02:21I'm going to set it to be nothing.
02:22But what I really want to happen is
02:24I want to animate this text.
02:26The problem is that by default, there's
02:27no way to animate the text.
02:29And I want it to type itself in.
02:30And I don't want it to be a fade.
02:32I actually literally want it to type in.
02:34And to make it type in, I'm going
02:35to have to create to be a little bit more clever.
02:38And to be more clever means that I
02:40have to figure out a way to get my copy to be a little bit
02:44more, well, I'll have to animate something else
02:47and not the actual copy.
02:49So to do that, I'm going to create a new variable.
02:51And I'm just going to call this ohelper, which
02:54is going to be an object.
02:57And I'm going to even set an initial property of this object.
03:00I'm going to say position.
03:02Let's say POS for position.
03:04I'm going to set position zero.
03:07Now what I'm going to do is I'm going to create an actual
03:09animation to that oanimhelper.
03:13And notice I've created a private variable already.
03:16It's called text tween, which is a tween light object.
03:20And what I want to do is I want to take that text tween,
03:24and I want to set it inside the value of our tween light 2.
03:29And that way we could interact with that tween
03:33and get more information from it whenever we want to.
03:36OK, so next I'm going to set what do I want to animate.
03:39I want to animate my ohelper.
03:45And I want it to take 10 seconds.
03:48And I want it to go to position.
03:51I want to take that copy that I have here for my sample text
03:54and just get the length of it, which I wrote this correctly.
04:05Because basically what I'm doing is
04:07I want to animate from zero all the way
04:09to the length of my copy.
04:12And I want to call the function on update.
04:16And I'm going to call the function on update,
04:17the callback on update.
04:19And I'll call it on text update.
04:23And I want to also send it a property.
04:25Let's talk about that in a second.
04:28So first of all, let me just close this up.
04:31And I'm going to close this up.
04:32Let's create that function, public function on text update.
04:45Let's bring it up so it'll be easier for you guys to see.
04:48OK, so we have here our function.
04:50The next step is we really want to gain access
04:52to our actual property.
04:53We want to know what property we're in right now.
04:56Now, I really want to have access to this ohelper
05:00because the ohelper is what's getting updated.
05:02Unfortunately for me, I created that variable
05:05in a scope where this function doesn't have access to it
05:07anymore.
05:08So I can't trace your ohelper.
05:10It doesn't exist anymore.
05:11If I wanted to, I could have put it out
05:13like I've done for my text tween.
05:15But unfortunately, I didn't do it.
05:18And I want to show you how do you actually send a property
05:20into the on update callback.
05:23So to do that, all you have to do
05:24is add another property here inside of those initiation
05:27properties and just call on update properties.
05:33And once you do that, you can literally
05:34just send inside an array.
05:36And in that array, I'm going to see if I could view Word Wrap.
05:42And in my array, I could just send whatever properties I want.
05:45So in this case, I want to send in my ohelper.
05:48So I'm going to send my ohelper into that array.
05:50And that's it.
05:51So my on update params is now going to have a property that's
05:55basically that ohelper would be that first property.
05:57So I could send you a few properties,
05:58and I would just list them all out in this function.
06:01So I'm just going to give this a name here.
06:04I'm going to call it o just for object to make sure
06:06that you guys are aware that it's passing through.
06:10It's not the same object that it was before.
06:12It's the same object, but it doesn't
06:14have to have the same name.
06:15And I'm going to give you a little trace.
06:17I'm going to trace that o pose.
06:19And once I do that, I should expect
06:21to get in every update, every time,
06:22every cycle of that animation, get
06:24an update of that position.
06:27So if we run this, we'll see that we're definitely
06:29getting that.
06:29We're getting these really crazy numbers here,
06:32which are not rounded.
06:33So we probably want to round them down,
06:35but this is exactly what we were hoping for.
06:37So I'm going to just round them down.
06:39I'm just going to create here a new variable for that.
06:41I'm going to call it index.
06:43It's going to be an integer.
06:44And I'm just going to put inside whatever value comes in.
06:47And automatically, when we assign a number of value
06:50that has a floating point into an integer,
06:52it will automatically just get rid of anything
06:54after that dot.
06:55I don't really want to update it up or down.
06:59I just want to chop out whatever's after the dot.
07:02And last but not least, for us to actually get our text
07:05animation to actually come through from beginning to end
07:08is to go to that T names again and set our text value
07:12to be the actual copy that we have here
07:15in that initial object that we have there, that text
07:17string that we have there, simple text.
07:19We want to basically chop out of that from index 0
07:23all the way to the index that we're at currently.
07:25So we want to take that text, and we
07:27want to slice out of it from position 0 all the way
07:32to the index that we're at right now.
07:34And once we're done with that, if I run my application one
07:37more time, you're going to see that now this copy is
07:39going to be starting to type in.
07:41And I think that's kind of cool.
07:44So it's just the first example of how
07:46do you create all these type of animations that
07:50enable you to basically, it doesn't
07:51have to be visual animations.
07:52You can animate numbers, and then
07:54use those numbers on update to create the animation you want,
07:57such as fade out events or fade in events.
08:01Not every animation has to be an animation that is visual.
08:06So by the way, when you hear fade ins and fade outs,
08:09that's basically how it's done.
08:10When you're creating a fade in and fade out,
08:12you're creating an animation of that fade.
08:15OK?
08:17Questions?
