In our last tutorial developed a dynamic motion blur. However, it was not completely dynamic since we were not able to add or subtract the number of instances. We referred to be dynamic because it was not created using hand-edited movie clips. One disadvantage of this approach is that once we compile the movie, the number of instances of the motion blur cannot be changed. In this tutorial we add new instances to the motion blur with the left button of the mouse.
IntroductionIn this tutorial we are going to develop an interactive motion blur. The user is going to be able to add new instances to the motion blur. Every time the client presses the left button of its mouse, the source movie clip is duplicated. Because of the implementation, we suggest to press at least ten times to make motion blur noticeable.
Interactive motion blurBased on previous code, we modify it by changing the constant variable HEARTS by hearts that hold the current number of instances. The code is presented below:
onClipEvent (load)
{
hearts=0;
Mouse.hide();
}
onClipEvent (unload)
{
for (i=0;i
eval("_root.heart"+i).removeMovieClip();
}
onClipEvent (mouseDown)
{
if (hearts<100)
{
_root.heart.duplicateMovieClip("heart"+hearts,hearts);
eval("_root.heart"+hearts)._alpha=hearts;
hearts++;
}
}
onClipEvent (enterFrame)
{
_x=_root._xmouse;
_y=_root._ymouse;
_root.heart._x+=_root._xmouse-_root.heart._x;
_root.heart._y+=_root._ymouse-_root.heart._y;
for (i=0;i
{
heart=eval("_root.heart"+i);
mult=(i+1)/(hearts+hearts);
heart._x+=(_root._xmouse-heart._x)*mult;
heart._y+=(_root._ymouse-heart._y)*mult;
}
} |
It should be familiar. Please notice that the first event handler was changed and that we added a new one. Except these changes, the code is similar to the last one. Because we want some interaction between the user and that movie clip, we set the number of instances to zero and let the user decide how many hearts is going to use. Every time the user presses the left button, we should duplicate the proper movie clip and place it in a higher layer to avoid collisions. We increment the alpha and the counter hearts too.
ConclusionThis example shows how to dynamically add new instances to create a motion blur. To do this, we duplicate certain movie and assign every new instance a different alpha. Now the user can decide how many instances will be sufficient. This code can be useful to understand duplication of movie clips and how to handle different instances –calling methods and changing or retrieving its properties.