2 Replies Latest reply on Jan 18, 2007 11:39 PM by Camus Miu

    Cloning an instance of a class

    Camus Miu
      I found the following sharing on cloning a class from Benz's web site.
      http://www.richapps.de/?p=34

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      creationComplete="initApp();">
      <mx:Script>
      <![CDATA[
      private function initApp():void
      {
      registerClassAlias("de.benz.something", Test);
      var t:Test=new Test();
      t.test="hallo";
      var newObj:Object=CommonFunc.clone(t);
      out.text+=newObj.test;
      out.text+=newObj.sayHello();
      out.text+=typeof newObj;
      }
      ]]>
      </mx:Script>
      <mx:TextArea id="out" left="15" top="15" right="15" bottom="15"/>
      </mx:Application>


      Anyway, I found that the clone is not really a class... the typeof traced is an Object
      so is the only way to clone a class is set up a public function in the class and return a new Class() with all the variables copied?