ActionScript Fundamentals pt. 1 / Writing Dot Syntax
Subtitles of the Movie
As with any language, in ActionScript 3.0 you need to learn the rules of grammar to put statements together. Dot syntax is the convention that ActionScript uses to put objects, properties and methods together in the statements. We've already looked at this. syntax. Let me review this in more detail in this movie. You connect objects, properties and methods with dots, or periods, to describe a particular object or process. Dot syntax lets you command objects with methods. The Flash method Hide, for example, written like this, when applied to the mouse object makes the pointer disappear. This example, james.eyes.color equals blue describes the object james that is linked to the object eyes; the object eyes in turn has the property color which is assigned the value blue. Notice that with. syntax you can use multiple dots to maintain object hierarchy. When you have multiple objects linked in this fashion it's often easier to read the statement backward so you could read this statement as blue is the color of the eyes of james. Now each method has its own set of parameters that you need to learn. If you consider the basic Flash action here, gotoAndPlay and then in parentheses page1 comma 10, gotoAndPlay is a method of the MovieClip class; the parenthetical parameters page1 and 10 refer to the frame label Page 1; that's in the quotation marks and in the Frame number, so the Playhead of the object will jump to Page 1 Frame 10 and then begin playing. So to summarize,. syntax allows you to create scripts with objects, properties and methods. Additional punctuation symbols let you do more with these single statements. Let me now review individual syntax elements starting with the semicolon. Use the semicolon, as I've already mentioned, to terminate individual ActionScript statements and start new ones. The semicolon functions as a period would in an English sentence. It concludes one idea and lets another one begin. I have a lot of examples so far of individual statements terminated with semicolons. Here are two more: stopAllSounds, open-close parens, semicolon and play. Let's go ahead and remove that extra space in between there. The semicolons here separate the statements so that all the sounds stop first and then the movie begins to play. Each statement is executed in order from the top down, just like a set of instructions written down in a paragraph of text. Curly braces are another kind of punctuation that you've already seen. ActionScript uses these quite frequently. We've seen these curly braces in relation to the function that we wrote up here. Curly braces group related blocks of ActionScript statements. When you assign actions to a button, for example, those actions appear within curly braces within the on release statement and that would be written like so. Let's add some spaces here - on release stopAllSounds play. In this case, both the stopAllSounds action and the play action are executed when the mouse button is released. Notice how the curly braces are separated on different lines to make the related script statements easier to read. The whole statement is terminated with that curly brace, closing curly brace and it started with the open curly brace up there on top. Now since methods can take many parameters, you'll use commas to separate each of these parameters. For example, the gotoAndPlay method that we saw in our first script can take two parameters - a scene name and a frame number or frame label - you would then separate the parameters with commas so that the ActionScript would look something like this. Let's go ahead and delete that and delete these others here to clean up our Script Pane here; gotoAndPlay Scene 1 is separated, that parameter is separated from the Frame 10 by the comma. Some methods have three, four, or even maybe ten parameters, but as long as you separate the parameters with commas Flash knows how to handle the code. Now as we've already seen, ActionScript 3.0 is case sensitive. You must be careful with the upper case letters that you encounter in ActionScript. Because this is always so problematic with folks new to programming in ActionScript I never use upper case letters in the script elements that I name, such as variables, instances and so on, but that does not mean that this issue still doesn't come up. Many ActionScript methods and other reserved terms use upper case letters quite liberally. For example, in our previous script we had gotoAndStop, the A in and and S in stop are capitalized, as well as the MouseEvent here, both first letters are capitalized - the M in mouse and the E in event. The bottom line is you must be very conscientious and careful about capitalizations in all of your code. Next, we get to colons. Colons identify object types as we used in this previous example of initializing this variable. The myName variable will contain data that's going to be in the format of a String. Likewise, another usage of colons is when we're creating Sound objects. Here myMusic is an instance of the Sound Class. Colons are important whenever new instances are introduced so that Flash knows what kind of data to associate with that object, so in other words this object, mySound is going to contain Audio data. This variable, myName will contain String data. Now so far I've been writing all of our ActionScript here in the Actions Pane, or Actions Window, but you can also create external ActionScript files that contain all of your scripting, so let me now move on to the next several movies and review the method of using external ActionScript files to provide scripts to your Flash projects.
Tutorial Information
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 