PDA

View Full Version : duplicate movieClip



Navarone
October 27th, 2009, 10:57 AM
I know AS3 doesn't have a duplicateMovieClip method anymore so how is this done?
I tried the following with little success.

Circle is a movieClip on the stage with instance name of circle. myEmptyClip is a movieClip in the library with the linkage set to myEmptyClip.



circle.addEventListener(MouseEvent.CLICK, makeNewCircle);
circle.buttonMode = true;

function makeNewCircle(event:MouseEvent):void {
var newCircle:myEmptyClip = new myEmptyClip();
newCircle.x = 300;
newCircle.y = 100;
addChild(newCircle);
}

senocular
October 27th, 2009, 11:21 AM
see:
http://www.kirupa.com/forum/showthread.php?p=1939827#post1939827

Navarone
October 27th, 2009, 12:04 PM
Ugh... Ok, so if you have items in a scrollPane and you want to add those to a container on stage but leave a copy in the scrollPane, this duplicateDisplayObject thingy will work for that?

Navarone
October 27th, 2009, 02:40 PM
Is there a working example of how your code works?

Navarone
October 28th, 2009, 10:39 AM
I don't understand how to use this code, is there a non-OOP version?

How you can have movie clips that are created dynamically and duplicate them if they are not in the library.


make sure you export for ActionScript the symbol you are duplicating

Do you create an empty movie clip in the library and use it whenever you need to duplicate something?

:cowboy:

senocular
October 28th, 2009, 10:43 AM
What are you talking about? :q:

[MuG]
October 28th, 2009, 10:56 AM
oook I've made a REALLY simple FLA and document class for you.

It should be simple enough to understand :)

senocular
October 28th, 2009, 11:04 AM
Oooo... that's not in the post, but in the class I have online.

Right. So the problem with symbols in the library is that without their own class definition ("exported for ActionScript") their constructor resolves to MovieClip and not a class specific to that object and its graphics as defined by its library definition. Since the function uses the constructor value to create the duplicate, the duplicate will obviously fail creating a simple, empty movie clip instead of an actual duplicate unless there's a tangible class to associate with that object

Oh, also note Flash Player 10 included a copyFrom() method in the Graphics class to copy Graphics drawings (I don't think this is in the function).

Navarone
October 28th, 2009, 11:05 AM
http://www.webriverinteractive.com/don/floorColorBasics_XML.html

I have 4 textures in the scrollPane, currently these textures are in the library. If you click on the texture it is removed from the scrollPane. So my AS2 brain is looking for away to duplicate it. Since I can't do that anymore in AS3, I need to find a method and you pointed me to your script which relies on having the symbol you want to duplicate in the Library. But eventually, I will want to use XML to populate the textures because there will be more of them, which means they won't be in the library so I don't know how to set their ActionScript for export. So I figure one way might be to have an empty clip in the library and you use this clip globally so to speak. Would that be a correct method. I don't think I have an issue with your script Senocular as much as I do with how to accomplish my goal here, which is to leave a copy of my texture in the scrollPane. Does that makes sense?

senocular
October 28th, 2009, 11:09 AM
Why are you duplicating them? I'm not sure that's what you want to do, especially if they're just bitmaps. If you're dealing with bitmaps, just reuse the bitmapData in a new Bitmap/drawing

Navarone
October 28th, 2009, 11:10 AM
;2512233']oook I've made a REALLY simple FLA and document class for you.

It should be simple enough to understand :)


Oops..I am using CS3.

Navarone
October 28th, 2009, 11:20 AM
Why are you duplicating them? I'm not sure that's what you want to do, especially if they're just bitmaps. If you're dealing with bitmaps, just reuse the bitmapData in a new Bitmap/drawing

I guess it's all part of the learning process I am going through. I just made movieClips of the pngs and set them in the scrollPane figuring that was the correct way. Looks like I need to back up and try a different approach.:}

senocular
October 28th, 2009, 11:31 AM
duplicateMovieClip was actually "abused" a lot in earlier versions of Flash. I put "abused" in quotes because, though it was used under hacky circumstances, it was really the only alternative until attachMovie. I'd like to think one of the reasons duplicateMovieClip wasn't in AS3 was to prevent its abuse. However, it has certain advantages in situations like drag & drop where you're making copies from a source that should start off with the same transformations as that source. Of course under any controlled environment, this behavior can be duplicated which I think was the expectation. It's not impossible, just creates an inconvenience more than anything else now. The lack of complexity of the duplicateDisplayObject function kind of reflects that, though it makes some assumptions that could be better handled in a controlled environment.

For bitmaps, though, you'll want to focus on reusing a single BitmapData for multiple targets since it would reduce memory use. That requires special attention based on the circumstance.

Navarone
October 28th, 2009, 11:50 AM
For bitmaps, though, you'll want to focus on reusing a single BitmapData for multiple targets since it would reduce memory use. That requires special attention based on the circumstance.

This would be hard to do if you have bitmaps of different textures wouldn't?

senocular
October 28th, 2009, 11:58 AM
it doesn't matter

Navarone
October 28th, 2009, 02:09 PM
I switched over to the BitMapData Class and my project is working now http://www.webriverinteractive.com/d...asics_XML.html (http://www.webriverinteractive.com/don/floorColorBasics_XML.html) , although I am having some problems with blendmode. It's not blendmode, but how I am creating the textures in photoshop. Anyway, I just wanted to say thanks for your help senocular.