Add the following method to the animal class:
private function onRollOver():Void {
useHandCursor = false;
balloon = attachMovie("balloon", "balloon", 0);
balloon._x = _xmouse;
balloon._y = _ymouse - 50;
balloon.name.text = name;
}
This method overrides the
onRollOver method of the MovieClip class. This script executes when the
dog or
cat instance appears on the stage and the user rolls the mouse over the instance. The purpose of this script is to display the value of the instance's
name property in a little window based on the Balloon clip in the library (we discussed the Balloon clip in Step 1).
The first line of the function sets the instance's
useHandCursor property to
false; therefore, the hand cursor won't appear when the instance is rolled over. The next line attaches the movie clip with the
balloon identifier in the library. The attached instance is given a name of
balloon and a depth of
0. The next two lines position the newly attached instance so that it appears at the same
x position as the mouse, but 50 pixels less than the
y position of the mouse; therefore, the balloon will appear slightly offset from the mouse cursor.
Remember that the Balloon movie clip has a text field instance called
name on its Timeline. When you attach that clip and give it an instance name of
balloon, you can set the text displayed in that field by referencing it as follows:
The last line of the script uses this reference to display the
name property of the instance in the text field.

Let's create the functionality that will remove the balloon when the user rolls away from the instance.