Introducing Script Assist


You are about to leave the safety of behaviors behind for the more sophisticated realm of ActionScript. Don't panic yet, however, because you won't get thrown into the thick of the language. You will meet Script Assist again in these next few exercises, and Script Assist will become your guide and companion through the ActionScript world. At least until you get good enough with ActionScript to go it alone. You can think of Script Assist then as training wheels for the ActionScript scripting language.

In Lesson 9, you will learn all about the general construction and usage of ActionScript and write your own scripts without using Script Assist. Here, you need to understand a few things about the language before moving on, so that you have a better understanding about what's going on in your Actions panel at any given time.

First, you already learned why something needs to have an instance name. Instance names are what you use to tell symbols or ActionScript objects what to do. They serve the same purpose in ActionScript that people names do in real life (although we have to be picker in ActionScript applications because no two instances can technically have the same name). If you're in a room full of kids, and you want to tell one of them to get you some aspirin, you don't shout "Hey kid, get me some aspirin!" because none of the kids will know which kid you're referring to. You have to call them by name: "Hey Cheyenne, go get me some aspirin!" As long as there aren't any other kids named Cheyenne in the room, she will (if she is being good that particular day) go and get you the aspirin you so desperately need when you're in a room full of children. So ultimately, we name symbols and ActionScript objects (such as the Sound object) so we can tell them what to do.

All symbols, named or otherwise, live somewhere on the Timeline. To tell it what to do, you have to path to it, which is geek speak for saying "Tell ActionScript where it is." When you path to something, you use a special notation called Dot Notation, which really means that you use "." characters instead of "/" characters to target an item. For instance, if you are in your living room, and you want your spouse to get your reading glasses from your desk in your upstairs bedroom (where he or she happens to be), the dot notation instruction to get your glasses when you shout to your spouse would look something like this:

this.upstairs.bedroom.desk.spouse.retrieveGlasses();

where this refers to your starting point, which is the living room, and upstairs, bedroom, and desk all refer to locations. spouse refers to an object that can do things (if he or she isn't too lazy), and retrieveGlasses() is the action you want him or her to take. retrieveGlasses() is also referred to as a method, which is something an object actually does. More on that in Lesson 9. If you don't have a spouse, you'll have to go get your glasses yourself:

this.retrieveGlasses(upstairs.bedroom.desk.glasses);

In this second example, upstairs.bedroom.desk.glasses refers to where your glasses are. The keyword this means you.

Keywords are special words reserved by Flash that have a particular meaning in ActionScript. When you are in the Actions panel and adding your own ActionScript instructions to control how an application works, you will see certain words change color. The color they change to depends on what the keyword is used for, but any time something changes color, it's because it's reserved by Flash for particular tasks. You should therefore be cautious not to name symbols or ActionScript objects with names that are otherwise reserved by Flash, such as getTimer. For now, don't sweat it too much. All your ActionScript in this lesson will be added with Script Assist and will be used to control buttons and movie clip Timelines.

There are many other aspects of ActionScript that you'll look at in Lesson 9. The ActionScript you add with Script Assist will let you test some of the features you added in the previous two exercises and will also provide the foundation for the interactivity used throughout the rest of the book.




Macromedia Flash 8. Training from the Source
Macromedia Flash 8: Training from the Source
ISBN: 0321336291
EAN: 2147483647
Year: 2004
Pages: 230
Authors: James English

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net