Personally, I use script to drive animation exclusively. However, script-driven animation is abstract, while tween animation is WYGIWYS, very handy.
I was told that, when Flash got its debut, animation is done by tween. OnClipEvent started since Flash 5 and scripts plays a heavy role since then.
However, it is painful if we add scripts to our movieClips that are contained in a tween. Error occurrs easily in this condition. How to make scripts work in a motion tween ? I dont have answers. But, I have seem many many "why" in FlashKit boards asking about this error. So, I think, we should try to clear something.
If two movieClip contains different onClipEvent block, then they are treated as different instances. They will be unload and reload. All the variables and state will lose and be reset to fresh new. What I mean the "same" block, I mean "completely" the same. Not a character more nor less. If you adding a blank line, add a comments, or even you clicke auto-format , all will make their onClipEvent block "different".
Here is a test:
I made a simple motion tween. A movieClip with a dynamic textbox in it. The tween consists of 3 keyframes. The tween make the square goes right to a keyframe and then tween back to the left. Please click play to show the animation.
Nnow we are going to add a script. The script is very simple. We use it to detect whether it is unload and reload. If it is reloaded, the count will be set to txt and 0, otherwise the count will keep accumulating;
Ok, we add script to the first mc in the first keyframe. MovieExplorer shows there is only one onClipEvent for symbol1. Please click the play button.
Is that what you expect ?
The script only works in the first tween. Every thing is reset when it meets the second keyframe as if it is another instance.
Now, we copy the onClipEvent block and paste to the clips in other 2 keyframes. Now, movie explorer tell us that, there are 3 onClipEvent block for 3 symbol.
Now click the play button. The count accumulates, and as we expected, counts increase. What I did not expect is that, the count in the first instance passes to the second instance along the tween.
The variable setting in the first keyframe, survives into the second keyframe. The count continue to sum up without reset to 0. Does that means they are the same instance. They pass through keyframes without reload and resetting !
Imagine the other way to do this tween effects.
Before we make a tween, we put this clip on the stage, add onClipEvnet block to make count accumulate. Then we insert 18 frames, insert 3 keyframe, select the second keyframe and drag the clip to the right edge. This is will create the same tween effect as we described above.
Now we check the onClipEvent block of them. Yes, every instance has the same onClipEvent block.Movie explorer also reports that we have 3 onClipEvent blocks. So, essentially, this is the same as that.
OK, lets go to the last step.
While all onClipEvent blocks are the same, we select the clip in the first frame and edit the onClipEvent block. I jsut Click auto-format. Nothing is changed about commands. Only the indent is re-arranged. These changes also appear in movie explorer.
Now click play button.
Now, they are different instaces now, because of the difference in onClipEvent block. The count-increasing script still works but they got reload and reset.
Instead of clicking auto-format, you can even press ENTER key, to make a blank line. That wil make them "different" too.
Most interesting thing is that, I remove the auto-formated onClipEvent block, and instead of copy-paste , I type my script by keyboard and besure the script is completely the same as other instances, word by word. Surprisingly Flash treat them as same instance then. Does Flash really do comparing the block ?
download the zipped fla of these movies
continue to see part 2.