Accessibility

TechNote (Archived)

How to change the property of a movie clip based on a the value of a variable

Follow the steps below to create the movie clip and set up the stage:

1

Begin by opening a new Flash document and immediately saving it.

2

Choose Insert>New Symbol. Leave the Behavior at Graphic and set the Name to Circle. Click OK.

3

Choose the circle tool, leaving the fill at red and the outline black. Draw a circle around the center centerpoint crosshairs.

4

Choose Insert>New Symbol. Set the Behavior to Movie Clip and the Name to Red.

5

Choose Window>Library to open the library for this document. Drag the Circle symbol out onto the stage and center it on the centerpoint crosshairs.

6

Choose Edit>Edit Movie to return to the main stage.

Right now the canvas should be blank, and there should be only two symbols in the library - the Red movie clip symbol and the Circle graphic symbol..

7

Choose the text tool and press the Text Field button at the bottom of the toolbar to enable the editable text field option. Draw a text box near the bottom of the stage, and type 450 into it.

You'll know you've got a text field (not a normal text block) if you can see its outline when it isn't selected.

8

Choose the arrow tool and then Modify>Text Field to open the Text Field properties window. Give it the name Varfield, leave all other options at their defaults and click OK.

Because the Text Field option was activated, this field will be a variable in addition to just holding text. It must have its own unique name, which allows it to be identified for access to its value.
9 Drag the Red movie clip symbol out of the library and onto the center of the stage, above the Text Field. Double-click it, and in the Definition tab, type 'redmc' into the Instance Name field. Click OK.
10 Choose Libraries>Buttons. Drag the Diamond Blue button from the Button library onto the stage below the Red movie clip symbol and resize as necessary.
11 Choose File>Save.

Before going on, make sure the document is set up correctly. There should be only three items on the stage - the Red movie clip symbol with the instance name redmc, the Diamond Blue button symbol and the Text Field with the Variable name Varfield. If there are any other symbols or shapes on the stage, delete them now.

To assign the property changes to the movie clip do the following:

1 Double-click the button to open the instance properties window, and click on the actions tab.
2

Click the + and choose Set Property. From the Set pulldown menu choose X Position. In the Target field type /redmc. In the Value field, type Varfield and change the value type to Expression. Click OK.

It is not necessary to 'Eval' the variable; simply referencing its name is sufficient. For more on Strings and Expressions, see page 196 in the Using Flash manual.
3 Choose Modify>Movie to open the Movie Properties window. Set the Ruler Units to Pixels, and click OK.
4 If you cannot already see the rulers in the editing window, choose View>Rulers to display them. Note where 450 is on the ruler. That is the target location for the red circle movie clip to move to.
5

Choose Control>Test Movie to open the Test Movie window. Click the button and watch the red circle move to 450.

Type another number, like 25, into the text field and click the button again. Watch the red circle move to the new location.

Note:The Set Property action is not restricted to buttons. It can also be assigned to a frame as a frame action.

Additional information

For another advanced tutorial using variables please refer to How to Duplicate a Movie Clip in Random Locations (TechNote 13940) orsearch the TechNotes using the keyword 'variable'.



AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support

Document Details

ID:tn_14039

Products Affected:

flash