开发者

actionscripts Clone the instances

Have anyone fou开发者_开发知识库nd any solution for cloning the "Instance name"?

Here is what i mean.

  1. Draw a random shape using flash not the actionscript
  2. Convert it to "Symbol"
  3. Assign the instance name to "cloneMe"

now try to clone it

The code should be something like this.

var newClone:MovieClip = cloneMe.copy()
newClone.x=100
newClone.y=50
addChild(newClone);


Try using ObjectUtil.clone(cloneMe)

It has been a while since I have dealt with symbols, but that should work.

You can see the documentation for ObjectUtil here.

If you do not have Flex available, you can also implement this function yourself. This is the same code that ObjectUtil.clone() uses:

var buffer:ByteArray = new ByteArray();
buffer.writeObject(value);
buffer.position = 0;
var result:Object = buffer.readObject();
return result;


I gave an answer in your previous question here: Actionscripts 3 Clone MovieClip

If you need to end with a MovieClip , you only need to add the resulting Bitmap to a MovieClip instance.

If you want to call a method , just create a Class with a static method. This can only be used to copy graphic data.

public class Utils
{
   public static function clone( cloneMe:MovieClip ):MovieClip
   {
      var mc:MovieClip = new MovieClip();
      var bmd:BitmapData = new BitmapData(cloneMe.width , cloneMe.height );
      bmd.draw( cloneMe);
      var bm:Bitmap = new Bitmap(bmd);

      mc.addChild( bm );
      return mc;
   }
 }

Then in Flash, provided that you've added the Utils class to your Library path. You can do this:

 var newClone:MovieClip = Utils.clone( cloneMe );
 //etc...


specifying your symbol as custom class might help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜