Archive for July, 2009

Q&A

What about submenus? Can a button in a pull-down menu then bring about another pull-down menu?

A1: Yes. You often see this in programs nowadays. You can simply place another pull-down movie clip inside your main pull-down movie clip. The new buttons will probably need to be shifted over to the right to avoid covering the buttons of the main pull-down menu. You can go many levels deep this way.

Q2: Can you have the pull-down menus slide in?

A2: Yes. Instead of having just two frames, you can use gotoAndPlay and have a series of movements along several frames and a stop() command at the end. You might want to use a mask layer to hide the buttons as they slide under the title. Or, you could have them dissolve in slowly.

Q3: Do pull-down menus always have to pull down?

A3: No. The buttons on a pull-down menu can actually expand up, to the side, or in any direction. But some scripts require that the buttons all touch so that the user can move the cursor from one to the other without ever leaving the movie clip.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

ts2ikx83rq

ts2ikx83rq

No Comments

Summary

Pull-down menus allow you to include many user options without taking up much space on the screen. You can implement pull-down menus in many different ways. Pull-down menus use a combination of button rollovers and clicks to expand and collapse lists of other buttons.

One way to make pull-down menus is to use a movie clip where the first frame represents the collapsed menu, and the second frame represents the expanded menu.

You can also create buttons on-the-fly by using the attachMovie and removeMovieClip commands. This enables you to create a whole system of buttons by only modifying ActionScript code.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Notice that when all the buttons

Notice that when all the buttons for the three lists in step 8 were created, “goto” was assigned at the thisAction property. This will come in to play with the buttonClickAction function. If the thisAction property is “goto”, the thisLabel property passed in will be used to determine which frame of the movie should be jumped to. In the case of our example movie, however, there is only a simple trace command used to demonstrate that the button does work.

Although this example contains a long script, it is not very complex. There is only some manipulation of movie clips, arrays, and variable objects, so there is a lot of code, but not much complexity.

Check out the movie 16dyanmicbuttons.fla if you haven’t yet done so. Try changing the labels of the buttons and try adding and removing buttons to see the effect. Get to know how the functions work.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

The buttonRolloverAction

The buttonRolloverAction function calls createButtonList with one of three different arrays and locations. The locations are planned so that the list of buttons appears under the button that is being rolled over.

The deleteAllButtonLists function makes all the three button lists defined in step 8 disappear. The result is that all three lists disappear, but the one list linked to the button being rolled over then reappears. So only one of these three lists is visible at a time.

The first step is to make an array that holds references to the three arrays of button lists.

Next, we’ll need a function that takes a list of buttons and removes all the movie clips, based on the mc property of each button created when the button was created.

Finally, here is the deleteAllButtons function that loops through the allButtonLists array and calls deleteButtonList with each one.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Next is an example of a list of buttons

Next is an example of a list of buttons. Each element of the array is a variable object that contains label and action properties:

After you have a button list, you can create the buttons by calling createButtonList:

buttonLevels = 1;
createButtonList(mainButtonList,100,100,”across”);

If you run the movie now, it will create three buttons. However, those buttons will do nothing if rolled over or clicked. So let’s create the buttonRolloverAction function. This performs a slightly different function depending on which of the three buttons is rolled over.

I’ll explain the deleteAllButtonLists function in step 9.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

For this function to work

For this function to work, it needs to get an array passed in as the parameter buttonList. This array will have custom variable objects with the properties label and action. You’ll see an example of these in the next step.

When each button is created, a new property of each object in the array is added. This property is called mc and is a reference to the movie clip created. So the array starts off containing the labels and actions of each button, but after createButtonList is done, each object in the array also has an mc property.

How did I get the numbers 20 and 100 in the preceding script? These are simply good distances to use according to the size of the buttons in my example movie. Larger buttons may require larger spacing, and smaller buttons may require smaller spacing. I got these values with a little trial and error. I also wanted to make sure that the vertical spacing was just right so that when the buttons are drawn in a vertical strip, they barely touch each other with no gap.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Here is a new createButton function

Here is a new createButton function. It looks just like the previous one, except that a new parameter buttonAction is used to set the variable thisAction. All that is done with thisAction is to send it along on calls to the two functions in step 2. An example of a thisAction value might be something like “goto” to signify that the buttons are supposed to perform a gotoAndStop command. It can be anything you want as long as the two functions mentioned in step 2 know how to interpret it.

This example’s script is long and has many parts. You may want to open the movie 16dynamicbuttons.fla and refer to its script to see how the parts fit together.

Here’s a function that takes an array of button values and creates an entire set of buttons. It uses the direction parameter to determine whether to space the buttons across or down.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

Task: Using Dynamic Buttons

Let’s create a complete system of buttons using what we just learned.

Start with the movie 16dynamicbuttontest.fla.

This basically calls the functions buttonRolloverAction and buttonClickAction whenever the button is rolled over or clicked. It is up to these functions to figure out what to do based on which button was clicked.

To help these two functions determine which button was clicked, two variables are passed back to the functions. You know that buttonLabel is the visible label on the button. The variable thisAction, which is not linked to a dynamic field, will be set when the button is created.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

You can test this script in the movie

You can test this script in the movie 6dynamicbuttontest.fla. The code there creates one button with the label Test Button.

You can create a whole series of buttons by using multiple calls to createButton. Or you can store the names of buttons in an array and use a for loop to call createButton with the name of each button. We’ll look at that technique in the next task.

Another problem that needs to be dealt with is how to get different buttons to react differently. The script in each movie clip’s button must be the same, so placing a gotoAndStop command in there means that all the buttons act the same. However, if you have the button call a function at the root level, that function can figure out which button called it and perform an action specific to that button.

Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours

No Comments

  • Partner links