I was just trying to duplicate a MovieClip when i got this a very good class from senocular library.
This class helps in duplicating the clips.
Here in example i have created a circle Sprite and i am duplicating it with the senoclular class.
The basic idea that i felt was that, you can duplicate the object after it is added to stage. Please reply me if anyone of you get any understanding of it. I am new to AS3.0 n hv just started learning.
Consider a simple class. This could be anything but for simplicity i am taking it.
doubleRed.as
package {
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.MovieClip;
public class doubleRed extends Sprite{
public function doubleRed()
{
graphics.beginFill(0x00ff00);
graphics.drawCircle(50,50,15);
graphics.endFill();
}
}
}
Look @ this Flash File code.
var db:doubleRed = new doubleRed();
addChild(db);
var newInstance:DisplayObject = duplicateDisplayObject(db, true);
newInstance.x = 200;
newInstance.addEventListener(MouseEvent.MOUSE_DOWN,dragme);
newInstance.addEventListener(MouseEvent.MOUSE_UP,stopme);
function dragme(event:MouseEvent):void{
event.target.startDrag();
}
function stopme(event:MouseEvent):void{
event.target.stopDrag();
}
var newInstance1:DisplayObject = duplicateDisplayObject(db, true);
newInstance1.addEventListener(MouseEvent.MOUSE_DOWN,dragme);
newInstance1.addEventListener(MouseEvent.MOUSE_UP,stopme);
I have just created the instance and first added it to the stage.
You can download all the realated files from below link.
-Nitin
No comments:
Post a Comment