Learn about writing ActionScript codes in this Adobe Flash CS3 Professional ActionScript Essentials training video series.


More DIY videos at 5min.com

Video Transcription

Now to write our ActionScript, we can just start typing right here in the line one, but I figured we could take a quick look at the Script Assist and also the Reference Features while we are getting things going. First of all, Script Assist. I will just click the Script Assist button to toggle it on and you can see that my window changes to show this large gray area. Now with this feature chosen, I can't just type down into the window. You will notice that if you try your keyboard that it's not enabled right now. So the Script Assist feature is basically going to do the typing for us. Now, for the first ActionScript that most people do, I would like to pick out one thing that's going to be a big helper to us and that's the Trace Function. Now let's see how to access this inside of the Reference Books. I am going to go over to Language Elements and inside there we have a few basic things that we will be using a lot of during our ActionScript writing and the one I am looking for in this case, is inside the Global Functions folder. Now Global Function is something that I can use anywhere in the program. We will just scroll down here and you can see we have got quite a few different global functions that we can use, but amongst them down here under T is trace. Now you can even see in the Script Assist window to add an item. What I will need to do is double-click it out of the Reference Book or just drag it into the Script window. So let's double-click our trace action. Now down on our Script window the Script Assist feature is already going ahead and starting the typing for us. It's typed out our trace function and added a few syntax elements that are needed for that function. The top of the panel is setup like a simple dialog box. Anything my trace function needs in order to operate, we are going to have to pop in here and it gives us a little display at the top of what the trace function is going to do. Now this is more of a helper function in the program, it will display any message that I gave it in the Arguments window including evaluating any expressions. So just to get things started, let's type in a little message to ourselves. I will just type in here, Welcome to Actionscript 3. This is just a message instead of an expression. So I am going to check off the Expression box and there we can see that it's completed writing the script for us. We can also point a few things out about basic syntax in the ActionScript language. First of all, whenever I have a function, I am always going to have parenthesis for that function and as parenthesis will contain any arguments that the function needs in order to operate. Also, we can see that each executable line of ActionScript ends with a semicolon, that basically tells the compiler that that line is finished and then it can go ahead and execute it. Now of course, if we turn off Script Assist, we would just need to type this function on in as we see it here and we will be doing typing a lot more instead of relying on Script Assist to do the typing for us. But with this first line of ActionScript, we can actually test it out to see what trace is going to do for us. Now to watch our ActionScript functioning inside the program, what we are going to need to do is make sure that we use Control and Test Movie. We won't be using the normal Play function since that won't enable most of our ActionScript. The Test Movie function as you probably know compiles a version of your SWF file and sends it out to a special version of the player so that you can see it running just like it would for the user with a few exceptions. Now there is a keyboard shortcut we can use for Test Movie, here on the PC its Ctrl+Enter and on the Mac its Command+Return. Now we can see our movie pops up in a normal window and I don't have any animation going on, so what we are seeing is those four bitmap graphics we have on the stage. But in addition to that panel, we are also getting the Output window and now we can see what the trace function does for us. It pulls up the Output window and places whatever message we put into it right there in the Output window for us. For a lot of people, trace and the Output window is the first line of communication with what's going on inside of your script. So we will be using the trace function throughout the lessons to be able to test different pieces of ActionScript and see how that code is working. For right now, the message that we placed in here isn't too useful, but at least shows us how that trace function is going to operate. Now since we are going to be using this Output window a lot more, let's go ahead and dock this with the others. I can grab the tab on the Output window and I can dock it down with my Properties Panel here at the bottom. So, we can easily view the results of our Trace statements. Now, let me close out of our Test window, go back to our Script and let's try doing a Trace without using the Script Assist feature. We can still make use of the Reference Library in very much the same way by simply double clicking and you can see that it starts writing the statement. The only difference now is that we are in charge of what we write and finishing out the statement correctly instead of leaving that all up to Script Assist. Now, what we will do is we will just put another message in here. You can see that we also have a Tool Tip up that showing us that we need a normal argument inside this function in order for it to work and I am going to add what's called the literal string by placing some text in quotes. So will start off with quotes, I will just type in a second message so we have something in our Trace window and of course, I will close the quotes and since this is the end of my line of script, I am going to go out to the end of the line and add a semicolon. We will do a quick test. Remember that's Ctrl+Enter on the PC and Command+Return on the Mac and there we can see out movie tested, but also in the Output window you can see that it's tracing both lines. Now, what that's also showing us is that our script is going to be executed one line at a time in order. So of course, we are going to be seeing the Welcome message traced first and we are going to follow that by a second message.