All of the submenu items in the Drop Down Menu component that we've been looking at are already using the Simple Script option for the Action parameter. The Simple Script option allows you to specify basic ActionScript goto, play, and stop commands either to control the main Timeline of the overall Flash movie or to control a Timeline of a movie clip.
The ActionScript commands supported by the Simple Script Action are some of the most fundamental ActionScript commands in Flash. Commands like gotoAndPlay are the sort of commands you learn when you are starting to learn ActionScript. Most Flash designers who are not highly proficient with ActionScript usually are at least familiar with these commands. However, entering these simple commands into a component's parameters is a little different from entering these same commands in the Actions panel, so let's look at how these commands work with components.
Select the instance of the Drop Down Menu component and open the Component Parameters panel. Click the Next Page button to go to the second page. Select Item 1 in the Menu Items parameter and then select Item 1 in the Sub Item For Main Item #1 parameter. The text fields should contain the text Curriculum and General Film (see Figure 5.23).
Figure 5.23: Item 1 is selected in both the Menu Items parameter and the Sub Item For Main Item #1 parameter.
Now click the Edit Click Action button. The Simple Script option is already selected in the Action parameter, and there is already a simple script in the Simple ActionScript parameter, as shown in Figure 5.24. As the text on the Simple ActionScript parameter explains, the code in the ActionScript parameter is executed when the user clicks the submenu button. However, the Simple ActionScript parameter supports a limited range of ActionScript commands.
Figure 5.24: Simple Script is already selected, and a script is already in the Simple ActionScript parameter.
Here are the commands that you can enter in the ActionScript parameter:
play(); stop(); gotoAndStop(); gotoAndPlay();
While these may not seem like very many commands, they can be adapted with a series of variations. For example, notice the command that's in the Simple ActionScript parameter in Figure 5.24:
This code is essentially a gotoandStop(); command. However, some additional elements have been added to the code. Let's evaluate how this code works.
The first part of the code is _root. The _root portion of this line of ActionScript code directs Flash to send the gotoAndStop(); command to the main Timeline in Flash.
This makes sense if you recall that a component is essentially a movie clip that has been converted into a different type of a Flash resource. So the gotoandStop(); command is being sent from inside of a movie clip. Therefore the _root portion of this line of ActionScript code sends the gotoAndStop(); command outside of the component back up to the main Timeline.
The next portion of the ActionScript is the word content. This is actually a reference to the instance name of a movie clip. To see this, close the Click Action Parameters screen and then close the Component Parameters panel. Now click the image of the three people to the left. Notice that when you click the picture, a blue outline appears around not only the image, but also the text and the two images on the right. All of these elements are surrounded by a blue line because they are all part of a movie clip.
Now press Command/Ctrl+F3 to open the Properties panel. Notice the instance name of the movie is "content," as shown in Figure 5.25. This instance name is the same "content" that is referenced by the ActionScript _root.content. In other words, content is a reference to the movie clip that has instance name "content."
Figure 5.25: The instance name of the movie clip is "content."
So the gotoAndStop command is being sent up to the main Timeline with the _root, and then the gotoAndStop is sent down to the movie clip with the instance name "content."
Where is the "content" movie clip directed to go to and stop at? That is what the "A1" in the gotoAndStop("A1"); portion of the ActionScript does. Whatever is in the parentheses is known as the "argument" of the gotoAndStop function. The argument qualifies the function. In this case, the argument tells the function where to go. When Flash sees something in quotations within the argument of a gotoAndStop or gotoAndPlay function, it knows that whatever is between the quotation marks is a frame label. Therefore the "A1" tells Flash to go to the frame labeled "A1" in the movie clip with the instance named "content."
The _root portion of the ActionScript tells Flash to look for the movie clip with the instance name "content" on the main Timeline. Without the _root portion of the ActionScript, the gotoAndStop(); command would be sent to a movie clip with the instance name "content," but Flash wouldn't look for that movie clip on the main Timeline-it would look for that movie clip within the component. Of course, there is no movie clip with the instance name "content" in the component, so the gotoandStop(); command would have no effect. Thus the _root portion of the code tells Flash to look in the right place for the movie clip with the instance name "content."
If you edit the movie clip with the instance name "content," you will see that the "A1" label is on frame 10 (see Figure 5.26).
Figure 5.26: The "content" movie clip contains content associated with each submenu item. The content for each submenu item is located on keyframes, and each keyframe has a label that is referenced in the gotoAndStop(); functions.
Therefore the ActionScript:
tells Flash to display frame 10 of the movie clip with the instance name "content." In fact, the same thing would happen if the command was written like this:
In this case, there are no quotation marks, and Flash knows that the number in the argument for the gotoAndStop function references a frame number. Therefore, this ActionScript would specifically direct Flash to display frame 10 of the movie clip named "content."
The gotoAndPlay, stop, or play commands can be used in the same way. The key is to send these commands to the place you want them. If, for instance, you only enter the command:
then you will be telling the component movie clip to play. If you want to direct the main Timeline to play, you need to write the command like this:
If you want to play a movie clip with the instance name "mysillyanimation," then you need to be sure there is a movie clip with the instance name "mysillyanimation," and you need to direct the command to it properly. For example, if the "mysillyanimation" movie clip is within another movie clip with the instance name "allanimations," then the command would look like this:
One final note before we move on. You can also use _parent, instead of _root. The _parent ActionScript directs the command up to the previous Timeline. In this example, _parent would accomplish the same thing because the main Timeline is up one Timeline from the movie clip that has been converted to the Drop Down Menu component. However, if the movie that contains the Drop Down Menu component is loaded into a separate movie, the _root command would route the command to the Timeline of that movie. In that case, you would need to use this command:
to send the gotoAndStop command to the proper place.
Now let's look at the last option in the Action parameter, the Advanced Script option.