Now, we have built a big construct around what is really a basic little animation principle here. You can see we have built all the things that we need. We needed a constructor, we needed to clear our variables, we needed to setup any other functions that we were going to use. We have also declared most of this one to be private so that we are not really messing with the internals of this one, we are really just getting the animation effect out of it, and it's a good idea to just check all of our declarations, in fact, I just caught something, I have set my init function up, but I haven't declared it as a function type.
Now, our classes are going to be really strict so I can fix that one right now. We are going to declare that as a function called init, and it's not a bad idea to go ahead and check the syntax. Looks like we are clean on syntax, so I am ready to test this out and see how it's functioning.
I am going to save my class file and we are going to set something absolute we can use it. Now, remember how we are going to call it, we are going to need to create a TypeThis object and we are going to need to add a couple of parameters in the constructor in order for it to function correctly. Let's go back to our newClasses.fla and set that up.
Now, it just so happens that we have got a text field in here called txtType and it's a multi-line text field already to be filled up. So, let's see if we can send something off to it.
Now, I am going to pull up our ActionScript, I am going to scroll down to the bottom and I will even add a comment line to break things up and we will make a call to work type this class. Now, I will need something to send to it, so, I provided a nice long thing so we can see the typing effect as it goes in. I will just minimize here and if you go looking in the Lesson 03 folder, there is a little text file called preamble.txt, I have got it open here and it just has the preamble to the constitution in it. That should be enough text for us to look at for a bit, I am going to copy that all out and I am simply going to bring it into my file and set that equal to a variable. I will just call it textToType and I will set that equal to paste and we have got all that dropped in here, here I'll setup Word Wrap so that we don't have to see it scrolling all off the side of the screen, and now, we have got something to type and we have got some place to type it too.
Moment of truth, we can see how our class is going to work. Let's create a TypeThis class object, I am going to call it typer, and it's going to be TypeThis class object, we will use the new keyword, will pull up our TypeThis constructor, and we will add in those parameters that we are looking for. I want to type the textToType and I want to type it into the field name textType and we are going to just close that off, and lucky for us we have got this color coding, I can see all these red ands and ins and dos in here, all of these blue color coded items and that basically is indicating that it's trying to read this not as a string, I should enclose that in quotes and then it will be a simple string that we are dropping into the variable.
Now, I think we are ready to test it out, we have got our text, we have got it supplied as a parameter for our TypeThis class and we have got our text field also setup, let's test the movie. We will move this out of the way and you can see that our text is being dropped in here, that little one character at a time trick is working nicely for us because it drops our text in.
Now, that was a pretty good example of an active class that we could reuse over-and-over again if we like. Each one of these classes that we have built you could make some modifications to them to make them a little bit more useful. For instance, I have got a couple of buttons dropped in here if you would like to play around with it a ReType button. Now, that's not too difficult, we would simply need to call the class again on the ReType. But you might have to play around with user interface for instance, if you click the ReType button before its finished typing you might have to add something to your class to make sure that you could clear the field before you started retyping into it.
I have also got a Quote button down here, so you could play around with instituting some of the other methods that we used in the SomethingNew class. The main point I wanted with each one of these classes is to get us thinking about the construction of classes and also to see where each one of these elements is going to go when we are building them up. You can get a lot of clues from saying, how the built-in classes work, and as you learn more about classes you will find you can add a lot more to them.
One final point I might make about the classes that we have built so far, specially the last class or TypeThis class is very dependent on us having a text field to type into. Now, that's very similar to the way we are using the Tween class. It's not going to work unless we actually have a movie clip to tween, but one place you can learn more about building classes is actually having classes build the elements that they need themselves.