Previous Tip  |  Next Tip  |  Design Tips   | [Bill's Home]

42. So you want to program?

It often takes software developers a while to get used to Macromedia Flash or Director. The reason for this is that the package was initially developed around stages, movies, and lots of other acting terms. This makes the environment difficult as the terms are new to software developers. Another problem is that software developers are used to creating code, which is executed, and run on the system. In Macromedia there has, in the past, been a great reliance on tweening, and scripting, which differs from code writing. These problems have now been overcome with Flash 5 which allows proper code to be written. Also with Flash MX the terms are started to become more focused on software development, such as the usage of components. Let's take a simple example of a Flash file with four movies: right, left, eyes and mouth:

This was simply setup by inserting the code (on Frame 2):

mouth._alpha=i;

and on Frame 5 the following can be setup:

i=i+5;
if (i>100) i=0;
gotoAndPlay ( 2 );

which add a value of 5 onto the alpha setting, until it gets over 100, where it will be set back to zero again. The first frame contains the initialisation of the i variable with:

var i=0;

The _alpha property of the movie is one of many properties which can be set, including: _x (x position), _y (y position), _height (the height of the movie), _scale (scaling of the movie), _url (URL of the movie), _xscale, _yscale, _visible (make it visible), and _rotation (rotate the movie).

So let's try modifying the rotation properties of two of the elements:

This was simply setup by inserting the code (on Frame 2):

right._rotation=angle;
left._rotation=angle;

and on Frame 5 the following can be setup:

angle=angle+10;
if (angle>0) angle=-90;
gotoAndPlay ( 2 );

which add a value of 10 degrees onto the rotation setting, until it gets over 0, where it will be set back to -90 again. The first frame contains the initialisation of the i variable with:

var angle=-90;

Now let's see if we can take a value from a pull-down menu, and add it as a property to the rotation. In the following example we can increment the angle of rotation by 1, 2, 5, 10 or 30 degrees. The pull-down menu is taken from one of the standard libraries.

This was simply setup by inserting the code (on Frame 2):

right._rotation=angle;
left._rotation=angle;

and on Frame 5 the following can be setup:

angle=angle+speed.currentvalue;
trace(speed.currentvalue);
if (angle>0) angle=-90;
gotoAndPlay ( 2 );

The speed object is the name of the movie for the pull-down menu (from the Smart Clips library). It sets the currentvalue for the increment in the angle.

If you want to try this is, you can down load the Flash source file here.

Next let's use the pull-down menu to set the alpha factor for the whole movie:

This was simply setup by inserting the code (on Frame 2):

right._alpha=alpha.currentvalue;
left._alpha=alpha.currentvalue;
eyes._alpha=alpha.currentvalue;
mouth._alpha=alpha.currentvalue;

where alpha is the name of the pull-down menu instance.