Flash 5: ScriptClips & SmartClips
September 07, 2001
by: Robert Ross
rob@trainingtools.com
User Level - Intermediate 
 
  Download Printable in FullSite

Building the ScriptClip
To build the ScriptClip, create a new Symbol (Behavior: Movie Clip / Name: script.alphaFadeIn) and make sure that there are two blank key frames, side-by-side, in what Flash will call Layer 1 by default. If you like, you can retitle the Layer. In the first key frame input the following statement using the Actions Panel (use the Panel in Expert Mode):

_parent._alpha+=5;

What does this do?
First, we designate the target object of the script by specifying the path, in this case _parent. By specifying that the script will affect the parent Timeline upon which we nest the ScriptClip we achieve our objective of making the script generic. The script will affect the parent Timeline of whatever Symbol we place an Instance of the ScriptClip on.
Second, we increment the alpha property of the parent Timeline by a fixed value of 5. The operator += is a shortcut. We could have made the statement appear as follows:

_parent._alpha=_parent._alpha+5;

In other words we take the current alpha value of the parent Movie Clip and add 5 to the current value. The += operator automatically takes into account the current value of the alpha property and adds the specified number to it, in this case 5. Thus this statement:

_parent._alpha=_parent._alpha+5;
can be expressed as I originally specified:
_parent._alpha+=5;

Both are valid. One if more efficient and "cleaner" if you like.
That’s it for the ActionScript in the first key frame Select the second key frame and input the following statement using the Actions Panel:

gotoAndPlay(1);

You have to keep in mind how the scrub (or Playhead) works in Flash. The scrub travels over each frame displaying the contents appropriately or executing scripts placed in key frames or on Instances. In this case, the scrub would pass through Frame 1 and execute the script to increment the alpha value. If we had only one key frame with the script to increment the alpha value within it, the script would only execute once, incrementing the current alpha property of the parent Instance by 5. Because we want the script to continually increment the alpha property we need to create a loop whereby the scrub, having executed the script in key frame 1 at frame 1, moves to key frame 2 at frame 2 and is told to return to the key frame at frame 1, thereby continually executing the script in key frame 1 and continually incrementing the alpha property.
We’re done creating the ScriptClip, now let’s see how we use it.


What is a Script File? Objective
Building the Script File Using the Script File
Added Flexibility: Using Smart Clips Creating a SmartClip
Using a ScriptClip Conclusion