Is there documentation on how flash manages named instances across key frames?

百般思念 提交于 2019-12-06 15:14:38

I have never seen this officially documented since I started with AS in Flash 5.

Your observations match mine, but another case is "same name, same type, new keyframe, different layer" which reinitializes the object in AVM1. I am not sure what AVM2 does, since I really try to avoid these situations, but this can be a decent way to get a MC to reinit on the timeline if you need to.

This is too long to post in the comments, but I discovered various other behaviors using frame scripts.

So far, an object with the same instance name on different key frames causes new instances to be created only when we have:

  1. different symbol type or
  2. same symbol type and different layer
  3. navigate to an intermediate key frame that does not contain the object

In other words, as long as instance name, symbol type, and layer the object is on remains the same from frame to frame, and each frame contains the named instance, then filters and transforms alone won't cause new instances to be created.

Things get interesting when ActionScript is involved.

---If you REMOVE THE OBJECT WITH A SCRIPT:---

Same instance name, same symbol type, same layer:

  1. If you remove the object with removeChild on frame 1, then on frame 2 no new object is created. In fact, the old object still exists, but it's not visible and NONE of the transforms from frame 2 are applied (i.e. the object retains its original size, filters, etc.).
  2. If you remove the object with removeChild on frame 1, and then immediately re-add the object, then it persists and is visible in frame 2, but still NONE of the transforms from frame 2 are applied (i.e. the object retains its original size, filters, etc.).

Same instance name, same symbol type, different layer:

  1. If you remove the object, a new one is created on the second frame as expected, since it was on a different layer. Being on a differnet layer is almost a guarantee that a new object will be created as you will see from the next statement...

  2. If you remove the object then immediately re-add it (removeChild(obj); addChild(obj);), then you end up with a DUPLICATE, because the new instance with new transforms on frame 2 is still created AND the original object remains (whereas if you had not removed/added it, the key frame change would have destroyed it).

Summary

Across key frames, the only things that will trigger the creation of a new object with the same instance name is if the object has a different symbol type or is on a different layer, or you visit a key frame that does not contain the object and then return to one that does. Nothing else will cause a new instance to be created. Removing the object with ActionScript (even if you immediately re-add it), will cause the player to NOT apply new key frame transformations to the object, but in and of itself will not trigger the creation of a new instance.

It isn't a documented behavior but your observations are correct. However, there's a potential snag that can happen to you if your two objects that share the same instance name are of incompatible types in that Flash might try to coerce the second (or all following) into "being" or trying to act like the first one it found. This may have been particular to fp9 but the behavior was 'scarring' enough to advise that you should NEVER have two different objects share the same instance name on the same timeline.

You might want to look at This blog entry on timelines and instance names that I wrote about the subject for a little more illumination.

One other thing that I may or may not have touched on adequately though, is that this behavior can also wreak massive havoc if you've nested timeline sounds in any movieclip that might be "skimmed" over if you use gotoAndStop/Play to "skip" around a timeline.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!