I needed cloning with inheritance one time.
I did it this way.
Worked perfectly...
*************** ValueObject ************
class ValueObject{
public function clone
(parent:ValueObject):ValueObject{
var clone:ValueObject= new ValueObject();
return cloneParams(clone,parent);
}
public function cloneParams
(clone:ValueObject, parent:ValueObject):ValueObject{
clone.setParent(parent);
return clone;
}
private function cloneValueObjectArray
(arrVOs:Array, parent:ValueObject){
var cloneArray = undefined;
if (arrVOs != undefined){
cloneArray = new Array();
for (var i=0;i<arrVOs.length;i++)
{
if (arrVOs[i] != undefined){
var voClone:ValueObject =
ValueObject(arrVOs[i]).clone(parent);
cloneArray.push(voClone);
}else{
cloneArray.push(arrVOs[i]);
}
}
}
return cloneArray;
}
}
***************************
And in a subclass you do something like this:
************** SubClass: ************
...
public function clone(parent:ValueObject):ValueObject{
var clone:ValueObject= new SubClass();
return cloneParams(clone,parent);
}
public function cloneParams
(clone:ValueObject,parent:ValueObject):ValueObject{
clone = SubClass(super.cloneParams(clone,parent));
SubClass (clone).type = this.type;
SubClass (clone).name = this.name;
SubClass (clone).productID = this.productID;
SubClass (clone).pages =
cloneValueObjectArray(arrValueObjects,clone);
return clone;
}
...
************************
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[EMAIL PROTECTED] Im
> Auftrag von JesterXL
> Gesendet: Donnerstag, 1. Dezember 2005 16:17
> An: [email protected]
> Betreff: Re: [flexcoders] instanceof on Object
>
> I just wrote clone methods. I need a true copy, so ensured each was made
> correctly. Easy for the simple ones (like Flex 2 events), harder for ones
> with arrays full of objects. I haven't figured out inheritanced yet, but
> since these VO's are strictly for the server guy and I to effectively
> communicate, they work well enough. Inheritance is for another day...
>
> class VO
> {
> public var id:String;
> public var name:String;
>
> public function clone():VO
> {
> var vo:VO = new VO();
> vo.id = id;
> vo.name = name;
> return vo;
> }
> }
>
>
> One for arrays:
>
> class Item
> {
> public var id:String;
> public var itemLabel:String;
>
> public function clone():Item
> {
> var i:Item = new Item();
> item.id = id;
> item.itemLabel = itemLabel;
> return item;
> }
> }
>
> class MajorVO
> {
> public var otherLabel:String;
> public var item_array:Array;
>
> public function clone():MajorVO
> {
> var mvo:MajorVO = new MajorVO();
> mvo.otherLabel = otherLabel;
> var i:Number = item_array.length;
> mvo.item_array = [];
> while(i--)
> {
> var old:Item = Item(item_array[i]);
> var ni:Item = old.clone();
> mvo.item_array[i] = ni;
> }
> return mvo;
> }
> }
> ----- Original Message -----
> From: Clint Modien <mailto:[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Thursday, December 01, 2005 9:51 AM
> Subject: Re: [flexcoders] instanceof on Object
>
> hey Jess... interested to know about the solution you went with on
> this...
>
>
> On 11/30/05, Paul Frantz <[EMAIL PROTECTED]> wrote:
>
> Hmm might be missing something here but Joe's suggestion in
> http://www.mail-archive.com/[email protected]/msg09275.html
> works ok.
>
> eg..
>
> Fred.as <http://fred.as/>
>
> class
>
> Fred {
>
>
>
> public function Fred() {}
>
> }
>
> App.mxml
>
> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml
> <http://www.macromedia.com/2003/mxml> "
> xmlns="*"
> initialize="myInitialize()"
> >
> <mx:Script>
> <![CDATA[
> import Fred;
>
> var f:Fred;
>
> function myInitialize():Void
> {
> f = new Fred();
>
> var g = Object(f);
> var _t;
>
> _t = new g.__constructor__();
>
> trace("_t instanceof Fred = " + (_t instanceof Fred));
> }
> ]]>
> </mx:Script>
> </mx:Application>
>
> ... produces 'true' for me.
> Cheers,
> Paul.
>
>
>
>
> -----Original Message-----
> From: JesterXL [mailto: [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> ]
> Sent: Thursday, 1 December 2005 05:55
> To: [email protected]
> Subject: Re: [flexcoders] instanceof on Object
>
>
>
> mx.utils.ObjectCopy does not do deep copies, nor work right:
> http://www.mail-
> archive.com/[email protected]/msg09275.html
>
> She's got array's in her too, so that definately rules in
it,
> and I need prototype integrity (subclass vs. superclass).
>
>
> ----- Original Message -----
> From: Clint Modien <mailto:[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Wednesday, November 30, 2005 2:09 PM
> Subject: Re: [flexcoders] instanceof on Object
>
>
> http://www.mail-archive.com/cgi-
> bin/htsearch?config=flexcoders_yahoogroups_com&restrict=&exclude=&words=mx
> .utils.ObjectCopy <http://www.mail-archive.com/cgi-
> bin/htsearch?config=flexcoders_yahoogroups_com&restrict=&exclude=&words=mx
> .utils.ObjectCopy+>
>
>
>
>
> On 11/30/05, JesterXL <[EMAIL PROTECTED] > wrote:
>
> ...I guess I'll have to implement a clone method on
all
> of my VO's. Any
> other solution/hack?
>
> ----- Original Message -----
> From: "JesterXL" <[EMAIL PROTECTED]>
> To: "Flexcoders" < [email protected]
> <mailto:[email protected]> >
> Sent: Wednesday, November 30, 2005 1:40 PM
> Subject: [flexcoders] instanceof on Object
>
>
> I have some VO's, and I use their class type to
render a
> form. My Dialogue
> I'm passing this VO into is bound to an object, like
so:
>
> private var formData:Object;
>
> <mx:TextInput text="{formData.label}" />
>
> When I call this method externally:
>
> myDialogue.setFormData(someVO);
>
> Function looks something like this:
>
> function setFormData(o)
> {
> for(var p in o)
> {
> formData[p] = o[p];
> }
> }
>
> My bindings work great. However, instanceof does
not.
> If I do this:
>
> formData = o;
>
> It DOES work; naturally because it's just a
reference.
> However, this
> dialogue works like a preferences. As such, I need
to
> create my own local
> copy; the above for loop is actually more involved
since
> I need a deep copy,
> and thus get a true, deep copy, not a reference.
>
> However, this in turn breaks my instanceof code.
I've
> tried:
>
> formData.__proto__ = o.prototype
> formData.__proto__ = o.__proto__
>
> ...none of which work. Frankly, I really don't care
> formData is truly a
> sub-class, I just want my instanceof to work, even
if
> it's taked.
>
> ???
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-
> archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor
---------
>
> --
> Flexcoders Mailing List
> FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-
> archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
> [EMAIL PROTECTED]
>
>
>
>
>
>
>
>
>
>
> *~~~****DISCLAIMER****~~~*
> This e-mail may contain confidential information. If you are
> not the intended recipient, please notify the sender immediately and
> delete this e-mail from your system. You must not disclose this email to
> anyone without express permission from the sender. The contents of all
> emails sent to, and received from, Optus may be scanned, stored, or
> disclosed to others by Optus at Optus' discretion. Optus has exercised
> care to avoid errors in the information contained in this e-mail but does
> not warrant that the information is error or omission free.
>
>
> --
> Flexcoders Mailing List
> FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-
> archive.com/flexcoders%40yahoogroups.com
>
>
>
> ________________________________
>
> YAHOO! GROUPS LINKS
>
>
>
> * Visit your group "flexcoders
> <http://groups.yahoo.com/group/flexcoders> " on the web.
>
> * To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
>
> * Your use of Yahoo! Groups is subject to the Yahoo!
> Terms of Service <http://docs.yahoo.com/info/terms/> .
>
>
> ________________________________
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
>
>
>
>
> SPONSORED LINKS
> Web site design development
> <http://groups.yahoo.com/gads?t=ms&k=Web+site+design+development&w1=Web+si
> te+design+development&w2=Computer+software+development&w3=Software+design+
> and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c
> =5&s=166&.sig=L-4QTvxB_quFDtMyhrQaHQ> Computer software
development
> <http://groups.yahoo.com/gads?t=ms&k=Computer+software+development&w1=Web+
> site+design+development&w2=Computer+software+development&w3=Software+desig
> n+and+development&w4=Macromedia+flex&w5=Software+development+best+practice
> &c=5&s=166&.sig=lvQjSRfQDfWudJSe1lLjHw> Software design and
development
> <http://groups.yahoo.com/gads?t=ms&k=Software+design+and+development&w1=We
> b+site+design+development&w2=Computer+software+development&w3=Software+des
> ign+and+development&w4=Macromedia+flex&w5=Software+development+best+practi
> ce&c=5&s=166&.sig=1pMBCdo3DsJbuU9AEmO1oQ>
> Macromedia flex
> <http://groups.yahoo.com/gads?t=ms&k=Macromedia+flex&w1=Web+site+design+de
> velopment&w2=Computer+software+development&w3=Software+design+and+developm
> ent&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.si
> g=OO6nPIrz7_EpZI36cYzBjw> Software development best practice
> <http://groups.yahoo.com/gads?t=ms&k=Software+development+best+practice&w1
> =Web+site+design+development&w2=Computer+software+development&w3=Software+
> design+and+development&w4=Macromedia+flex&w5=Software+development+best+pra
> ctice&c=5&s=166&.sig=f89quyyulIDsnABLD6IXIw>
>
> ________________________________
>
> YAHOO! GROUPS LINKS
>
>
>
> * Visit your group "flexcoders
> <http://groups.yahoo.com/group/flexcoders> " on the web.
>
> * To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED] <mailto:flexcoders-
> [EMAIL PROTECTED]>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
> <http://docs.yahoo.com/info/terms/> .
>
>
> ________________________________
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/