Scripting the Quicktip Interaction
Each element is in place: the button, the movie clip, and the dynamic text field inside the movie clip. You're now ready to write the script that makes the interaction work. Before you start, you should plan ahead and spell out what you're trying to do, as well as the role each object will play.The three objects you'll use have the following instance names: tempest_1_btn, quickTip_mc, and quickTip_txt. Remember that quickTip_txt is inside quickTip_mc.You'll need the script to make quickTip_mc invisible by default.You'll need the script to do the following when the user rolls over tempest_1_btn: make quickTip visible, position it near the user's mouse, and populate the Dynamic Text field with the correct text.You'll need the script to make quickTip_mc invisible when the user rolls away from it.
It's usually easier to write a script when you know exactly what you're trying to do.
1. | Click Frame 1 of the actions layer, and open the Actions panel (F9). |
The Actions panel opens, and, as you can see, already contains a small script that stops the movie in the first frame, as well as the script you entered earlier to program the Down button.You'll add the rest of the scripts for the upper half of the Inferno to this frame.[View full size image]

Outlining the code with comments helps you write the code now and also documents the code, which makes it easier to maintain later.[View full size image]

3. | Below the first comment, enter the following code block: quickTip_mc._visible = false; |
NoteThe spacing around the equals sign is optional. _visible is a property of all movie clips. It has two settings, TRue and false. As you have probably guessed, TRue is the default. By setting it to false, you make the movie clip instance invisible, because this code is executed before the movie clip instance has a chance to display.The dot (.) between the instance name and its property, called an access operator, implies a relationship: the item on the right belongs to the item on the left. You'll use access operators a lot in ActionScript, because they work almost like an addressing system, enabling you to tell ActionScript where to look for something in the document hierarchy.The equals sign (=) that separates the two halves of the line is called an assignment operator. Use the equals sign when you want to assign a particular value (in this case, false) to a given object asset (in this case, the quickTip_mc instance's _visible property).[View full size image]

4. | Choose Control > Test Movie. Verify that the movie clip instance is not on the stage. Return to the Flash authoring environment. |
If the movie clip is not visible on the stage, you know your script is working properly. If it is visible on the stage, make sure the instance name in the Property inspector with the instance selected is spelled exactly the same as the instance name written into the ActionScript.Any time you add new functionality to a script, you should test the movie to verify that everything went as expected. If you wait and test later, it can be hard to debug if something does go wrong.
Lesson 10 (the button_btn.onEvent = function() {...}; syntax). Now you're causing a series of actions to occur when the user rolls over the tempest_1_btn instance.This group of commands is generally easy to read. The first command makes the movie clip instance visible again, since its default state is invisible.The next two commands, which set the instance's _x and _y properties to _xmouse and _ymouse, have to do with positioning. As you'll recall from the Fireworks lessons at the beginning of the book, every graphic object is positioned relative to the top-left corner of the canvas/stage. This value is stored in its _x (horizontal position) and _y (vertical position) properties. Likewise, Flash stores the current position of the mouse in the built-in _xmouse and _ymouse properties. Thus, in these two lines of code, you're telling Flash to position the top-left corner of the movie clip instance in the same place as the mouse, which ensures that the user easily associates the text in the quicktip with the screen element (in this case, the tornado) that she or he has just rolled over.In the last statement inside the block, you set the value of the
6. | Test the movie again. Roll over the tempest and verify that the movie clip appears and that its text displays. Return to the Flash authoring environment. |
So far, so good. The movie clip and text shows up. The only problem is that it never goes away.[View full size image]

7. | After the final comment, insert the following code: tempest_1_btn.onRollOut = function() { |
property contains, because the whole movie clip is invisible, and the next time it appears it will have new positioning and
8. | Once again, test the movie and verify that the quicktip appears and disappears as expected. |
This time, the quicktip disappears when you move away from the button.
9. | Copy and paste the hotspot you've been working on so that a hotspot covers each of the remaining tempests on the map. Change the instance name to tempest_2_btn, tempest_3_btn , and so on, so each is unique. |
Because there are multiple tempests on the map, you should make all the buttons pop up the quicktip.
10. | Select Frame 1 in the Actions panel, copy and paste the two functions associated with tempest_1_btn, and change the instance name in the ActionScript to tempest_2_btn and tempest_3_btn . |
[View full size image]

11. | Repeat this process to put hotspots over the storms, wars, and swamps, as well as the Castle of Reason and the City of Dis (see the figure for guidance). Then, go into the Actions panel and copy and paste the two button functions for each new hotspot you created, changing the instance names and the text that appears, using text from script_infern228.txt. |
[View full size image]



12. | Save and test the file one last time. |
The quicktips should pop up for each of the items on the screen.