|
|||
| week 10b - director basics, director scripting basics | |||
director scripting: |
Director uses the Lingo language for scripting, which is similar to Flash ActionScript in that it uses an event model and object properties. It is different from ActionScript in terms of syntax. For example, it does not use the ";" at the end of each statement line.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| kinds of scripts : |
Cast scripts are created by selecting the desired cast member, and then clicking on the script icon to open the script editor. movie: A kind of global place to put code, similar to the way the first frame of Flash movies are used. These scripts can handle events such as on prepareMovie, on startMovie, on stopMovie, as well as defining the equivalent of user defined Flash functions. behavior: These scripts are designed to be attached to sprites or frames in the movie. They are generic code that can be attached to many different objects. We will use these kinds of scripts most. parent: These are special scripts used for object oriented programming, enabling code centralized in one place to be "inherited" by other scripts. The parent script's handlers can be used by "child" scripts that are derived from the parent. cast: A script that is associated with a specific cast member. The code goes with every instance of the cast member that's placed on the stage.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| LINGO vs. JavaScript : | There are two languages supported in Director, Lingo and JavaScript. We'll be learning JavaScript since it is very close to ActionScript in Flash. For JavaScript code to work, you must select the language in the pulldown menu in the upper left corner of the script window.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| identifying sprites : | In Director, sprites are always identified by their current channel number or channel name (this is new for MX 2004). Unlike Flash, there is no naming system for sprites in Director as there is with movieClip instances in Flash. To move a sprite that's in the third channel to an X,Y position of (200, 100), the code would look like this:
To make code more generic, it is possible to identify the current sprite without naming the actual channel number of the current sprite. This technique is similar to using the "this" keyword in Flash.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| properties : | Sprites and other objects in Director have properties that are similar to Flash properties. Some commone ones are:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| event handlers : | Director has event handlers the operate in the same manner as those in Flash. The Director event handlers always have the form:
For example, code to move a sprite across the screen might be written as: In Flash:
In Director:
Another example would be code to keep the main timeline in Director on the same frame. Frame code in Director uses events, where code in frames in Flash does not. This is the Director equivalent to Flash's frame script: stop();
Please see the Director Help system for detailed explanations of these frequenty used events. Mouse related events: Frame related events: Keyboard related events: Example use of the keyboard event handler
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if statements : | If statements in Director JavaScript are the same as in Flash. Flash:
Director:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| trace() : | For debugging purposes, Director uses the same trace() function as Flash does. Flash & Director:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| comments : | Comments allow you to put in descriptive text in your code, or temporarily
remove code so it doesn't run, but leave it in the script. A nice feature
in Director enables you to select a set of code, and click on the comment
button in the script window to instantly comment out (or remove comments
from) all of the selected text. Flash & Director : // this is a comment |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| sample director movie : | download firstDirector.dir & quicktime movie (1.5meg) behavior code on 1st and 10th frames:
behavior code on left sprite:
behavior code on right sprite:
behavior on the "script" text sprite:
|
| all materials on this web site © copyright 2004, Philip van Allen |
top |