You can use this technique for typed objects too, you just need to
ensure that you have registered a remote alias for the class. This is
because ByteArray serialization is really making use of a player feature
that is intended for sending AS3 data to remote agents.
import com.something.FooObject;
//...
private static var reg:Boolean =
flash.net.registerClassAlias("com.whatever.FooObject",
com.something.FooObject);
See:
http://livedocs.adobe.com/flex/2/langref/flash/net/package.html#register
ClassAlias()
Or, if you're using MXMLC or Flex Builder to compile a Flex application
you can make use of the special class-level metadata by declaring
[RemoteClass(alias="com.whatever.FooObject")] above your class
definition.
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Troy Gilbert
Sent: Tuesday, May 29, 2007 1:14 PM
To: [email protected]
Subject: Re: [flexcoders] Re: Converting the output of ObjectUtil.copy()
to custom type
All of these techniques copy generic objects (as in property containers,
name value pairs). Typed objects do not function in exactly the same
way. As a result, you can't clone them generically.
Troy.
On 5/26/07, Lucas Pereira <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
Hi.
Right now I'm having the same problem.
I even found this:
public function cloneObject(o:Object):Object
{
var bytes:ByteArray = new ByteArray();
bytes.writeObject(o);
bytes.position = 0;
return bytes.readObject();
}
but ended up always in the casting problem :(
Had you find an answer?
Thanks
Best regards
--- In [email protected]
<mailto:flexcoders%40yahoogroups.com> , "ben.clinkinbeard"
<[EMAIL PROTECTED]> wrote:
>
> Does anyone know how to do this? Neither casting nor the "as"
operator
> are working.
>
> var foo:FooObject = new FooObject();
>
> // this doesn't work
> var fooCopy:FooObject = FooObject(ObjectUtil.copy(foo));
>
>
> // neither does this
> var fooCopy:FooObject = ObjectUtil.copy(foo) as FooObject;
>
> Thanks in advance for any pointers,
> Ben
>