Answered
Duplicating Loaded SWF, No Actionscript??
So... in writing a Flash based game, I have the main SWF and
its associated classes at one point loading a single SWF that
represents an animated sprite in the game. I want to use this
sprite multiple times in the game, so I duplicate it after loading,
and expected that this would work. Unfortunately, after duplicating
the loaded SWF, it seems to be ignoring timeline actionscript calls
such as gotoAndPlay().
Here's the setup:
The loaded SWF that contains the animated sprite has a single layer on the timeline, and basically has a number of labeled frames dedicated to each animation -- i.e., there is a "walk_east" frame, which cycles through a character walking east, and at the end of that animation, has a gotoAndPlay("walk_east") command on one of the frames that sends it back to the beginning of that particular animation to repeat the whole ordeal. The frame after that one might be "walk_west", and contain the walking west animation, etc. The very first frame of this SWF has a simple "stop()" call in it, so nothing animates until the main SWF tells this loaded SWF to do so (via a gotoAndPlay() call). This SWF has a base document class called "Actor".
The main SWF loads this SWF using a typical Loader. Then, to duplicate the loaded SWF, I settled on doing something like this, where "clip" is a reference to the loaded SWF loader:
var swfClass:Class = clip.contentLoaderInfo.applicationDomain.getDefinition("Actor");
var clone = new swfClass();
I can create all the duplicates I want, no problem. However, as soon as I start playing one (i.e., "clone.gotoAndPlay("walk_east"), it will just cycle through the entire timeline of the loaded / duplicated sprite SWF -- ignoring the various actionscript code on frames that SHOULD have it repeating the specific animation cycle I want... and despite the fact that when played stand-alone, the same SWF does not display this behavior.
Its as though duplicating the movieclip causes the duplicated SWF to lose its actionscript on the timeline?
Does anyone have any ideas? Is this expected behavior? I can't imagine this is how it should be -- I only want to load the SWF sprite one time, to save bandwidth, and then duplicate it as many times as I want in the game. This has had to be done before... I can't imagine developers simply reloading the same SWF multiple times if they need the same SWF to be used multiple times -- i.e., multiple enemies of the same sort.
Or am I just making this more difficult than it has to be? Please help!
Here's the setup:
The loaded SWF that contains the animated sprite has a single layer on the timeline, and basically has a number of labeled frames dedicated to each animation -- i.e., there is a "walk_east" frame, which cycles through a character walking east, and at the end of that animation, has a gotoAndPlay("walk_east") command on one of the frames that sends it back to the beginning of that particular animation to repeat the whole ordeal. The frame after that one might be "walk_west", and contain the walking west animation, etc. The very first frame of this SWF has a simple "stop()" call in it, so nothing animates until the main SWF tells this loaded SWF to do so (via a gotoAndPlay() call). This SWF has a base document class called "Actor".
The main SWF loads this SWF using a typical Loader. Then, to duplicate the loaded SWF, I settled on doing something like this, where "clip" is a reference to the loaded SWF loader:
var swfClass:Class = clip.contentLoaderInfo.applicationDomain.getDefinition("Actor");
var clone = new swfClass();
I can create all the duplicates I want, no problem. However, as soon as I start playing one (i.e., "clone.gotoAndPlay("walk_east"), it will just cycle through the entire timeline of the loaded / duplicated sprite SWF -- ignoring the various actionscript code on frames that SHOULD have it repeating the specific animation cycle I want... and despite the fact that when played stand-alone, the same SWF does not display this behavior.
Its as though duplicating the movieclip causes the duplicated SWF to lose its actionscript on the timeline?
Does anyone have any ideas? Is this expected behavior? I can't imagine this is how it should be -- I only want to load the SWF sprite one time, to save bandwidth, and then duplicate it as many times as I want in the game. This has had to be done before... I can't imagine developers simply reloading the same SWF multiple times if they need the same SWF to be used multiple times -- i.e., multiple enemies of the same sort.
Or am I just making this more difficult than it has to be? Please help!