This content has been marked as final. Show 13 replies
maybe load it 2xs?
You cannot duplicate loaded SWF files in AS3. All you can do is use addChild multiple times (perhaps with a for loop depending on your situation) to add the DisplayObjectContainer to the Display List as many times as you need.
You cannot do it. Even when using addChild, if a child placed somewhere is added again somewhere else, then it is removed from its previous parent and attached to the new one. Or if inside the same parent, it is detached from this parent and attached to the last position of the display list.
I've tried using multiple addChild for the same"loader.content" - and it doesn't do anything. It adds the first child - and then all subsequent children are not added - and don't even exist. It will allow you to add the same "loader.content" to a different display object - but it removes the first reference.
I haven't seen anything in LiveDocs or on this forum - you know if that's an official answer from Adobe? (many people, including myself, have been requesting this change since flash 5).... Given the silence from Adobe - I would guess that your answer is correct.
have you tried storing the loader.content to a MovieClip object and then using a for loop to create new holders that you can place that loaded content into??
I've tried it similar to that method - and no dice. Then I just did it now with your code - and still doesn't work. It places the loaded MC in the last created instance.
Does it work on your end? (Just in-case I'm missing something).
Well definitely and finally: Still unable to duplicate loaded SWF files? Yes, still unable to duplicate loaded SWF files.
what are you targeting with your loader's complete event listener?
loader.content.addEventListener( or ....
The addEventListener isn't where I'm having a problem. That's all working fine - when the file load completes - my "attachmovie" fires -
and I do -
var loadedA:DisplayObject = loader.content;
var loadedB:DisplayObject = loader.content;
loadedB.y = 100;
Only loadedB will appear on the stage. You can change the "loader.content" to "e.target.content" - and the same problem will continue.
Yep, what I am trying to say is I know a lot about ActionScript. And when I say there is no way, it means, there is really no way to duplicate a loaded movie. You can try many thing and you will never get to do it. The only thing possible is loading an SWF with all its content placed inside a movie clip, and export it for ActionScript so once loaded you can attach the clip many times in the loaded movie.
That is certainly an option juan. Create an empty movie clip using the environment and then place your loader AS into the first frame of that movie clip. In the library, export the movie clip for AS and give that movie clip it own class name (you may get a message that flash will create a class file for you which is fine). To create duplicate clips, all you need to do now is simply call that MovieClip's constructor and add it to the display list.
var _myMC:MovieClip = new MovieClipClassName();
addChild( _myMC );
You could make this call as many times as you like to in theory "duplicate" your clip. Although this is actually more like using attachMovie again and again.
In AS2 - any movie clip that I needed to reproduce multiple times, I did just that -I placed it into the library and duplicated the symbol. Works fine - and as SymTsb mentioned it's easy to do with AS3.
However, I'm using XML to load in a variety of swfs, and just incase it's a file that's already loaded, theoretically it would be faster (and less calls to a server) to just duplicate the existing swf (or jpg, or gif, or mp3, or png) instead of calling and reloading it again into a different location in the master clip. And, I'd rather not add to the library and bloat the master clip with symbols that may only be dup'd two or three times.
You're right Juankpro this problem isn't new - it's been around since flash 5 - Every time Adobe/MM comes out with a new version I'm just hoping that they fix it.
One alternative method would be to use the bitmapData,draw() method to make a copy of the MC. Then, when you need that visual representation in another clip, simply create a bitmap object and pass in the bitmapData instance in the constructor.: bitmap1=new bitmap(bitmapdata1);
Viola, bitmapData is not passed by reference, it is duplicated every time you use it.