macromedia DIRECTOR MX 1002004 training from the source [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

macromedia DIRECTOR MX 1002004 training from the source [Electronic resources] - نسخه متنی

Dave Mennenoh

نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
تنظیمات قلم


اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
لیست موضوعات
افزودن یادداشت
افزودن یادداشت جدید

Creating a Pause with Lingo

As we mentioned, Lingo is Director's scripting language, and it's capable of programmatically controlling nearly every aspect of the application. Lingo has evolved into a very robust, fast, object-oriented language that is easy to learn but hard to master. A very cool feature introduced with Director 6.5 is behaviors. The great thing about behaviors is they immediately expose you to object-oriented programming in a very natural manner.

Let's create a simple behavior that pauses the playhead, and then instantiate it multiple times to allow pausing at each section in the movie.


Double-click in the behavior channel at frame 10the end of the "intro" sectionto open a script panel.

A script panel, or window, allows you to enter Lingo or JavaScript code using a familiar word-processor like interface. As you enter code, it is both formatted and colored, allowing you to more easily pick out mistakes as you enter them.

At this point the first thing you want to do is to make sure the scripting syntax is set to Lingo. In the script panel's toolbar, at the left side, is a little drop-down menu that will either say Lingo or JavaScript.

[View full size image]

If the syntax is set to JavaScript, you can easily change it back to Lingo. First, choose the script that Director automatically placed in the script panel by pressing Ctrl/Cmd+A. With the entire script elected (all three lines of it) press the Delete or Backspace key to delete the script. Finally, use the Script Syntax drop-down to change the syntax to Lingo, and then close the panel. You will notice that no new cast member was created, because there were no lines of script, but you did change the default syntax to Lingo. Repeat step 1 now by double-clicking in the frame channel at frame 10 to open a script panel with Lingo as the syntax.


In the script panel, complete the behavior that Director started for you, and name your script loop_on_frame.

Director will automatically begin a script for you if you create the script on a frame or a sprite. If created on a frame an exitFrame handler will be started, as is the case here. Like many of the newer development applications, Director uses an event-based system. Events are just things that happensuch as a keystroke, a mouse click, or in this case an exit frame. Some events, like the exit frame, are generated by Director during the normal course of movie playback. Other events, such as a mouse click, are generated by the user. You write handlers to capture and handle the eventa handler begins with the keyword on. If no handler exists for an event, it simply disappears. It's actually a tiny bit more complicated than that, but this is all you need to know for the time being.

Enter line 2 to complete the default exitFrame handler:

1 on exitFrame me
2 _movie.go(_movie.frame)
3 end


As stated in the Elements and Format section of the Introduction, code line numbers are there for identification purposes only and are not to be entered.

Don't forget to give the script its name.


In the Script Panel's toolbar press the lightning bolt, which recompiles all scripts. When you recompile, Director takes the code you wrote and compiles it into a form readable by the computer.


If you don't see the lightning bolt in the toolbar, you may need to expand the script window horizontally to be able to see all of the buttons available.

Can you tell what line 2 does? As Director plays through each frame of your movie it generates a few different events, such as enterFrame and exitFrame. These are generated on each frame as the movie plays. So when the playhead reaches frame 10 and Director generates the exitFrame event, your on exitFrame handler will catch it and execute line 2. In plain English, line 2 says, "Hey movie, go to the frame I'm on right now."

If you wanted to go to frame 20 you could have said _movie.go(20). Instead, _movie.frame is a movie property that contains the frame the playhead is currently on. This will allow you to use this ehavior on any frame of the movie, instead of having to write separate scripts for each place you want to pause.

Close the script panel. You will note that cast member 6 has now been created. The little yellow flower-like icon means the member is a behavior:


Play the movie.

When the playhead reaches frame 10, it will pause. However, it's not actually paused as would happen if you used the tempo channel's wait options. Instead each time the playhead tries to leave the frame, the exitFrame event is generated, and captured by the script, which sends the playhead back to the frame it's already on. In this manner the movie continues to play, but in a single frame, and will not freeze Lingo or other objects like using the Tempo channel would.


From the cast, drag the loop_on_frame script and drop it onto frame 34 in the Score's script channel, at the last frame of the project1 section. Repeat, but this time drag the script to frame 59the last frame of the project2 section.

The behavior channel, in your Score, should now appear like the following, with the script you just created used in frames 10, 34, and 59:

[View full size image]

It seems natural, doesn't it? You created one general behavior script and used it on three different frames. In some languages, the script you created would be called a class, and using it in three different spots is known as instantiating it. If you edit the script, it changes in every location it's used. This is just a taste of what you can do using behaviors, as you will learn in later lessons.

I should also mention that while behaviors are somewhat like classes, they are specialized forms of classes that are attached to sprites and frames only. Lingo does have a more formal definition of a class, called a parent script, that you will learn about when you do the third project in the book: the 2D game.

Right now, if you played the movie it would play until it reached one of the scripts, pause, and do nothing more. So our next step is to start working on the buttons that will send the movie to the appropriate section.

This is also a good spot to again save your progress, so press Ctrl/Cmd+S.

/ 165