Moments of Flash, ActionScript, Flex

Discuss, challenge, inspire, connect, discover...

Subscribe
Add to Technorati Favourites
Add to del.icio.us

My opinion is that the following is a big bug.

When serializing/cloning an object that has required constructor parameters, you receive an error telling you the arguments are incorrect. Note: the following is just an example using a "native" flash class. Really, you should never have to serialize or clone an Event, so please just see it as an example class as the type of class isn't the point.

[actionscript]
import flash.net.registerClassAlias;
import flash.events.Event;
import mx.utils.ObjectUtil;

flash.net.registerClassAlias("flash.events.Event",Event);
var event:Event = new Event(Event.CHANGE);
var eventClone:* = ObjectUtil.copy(event);
trace(eventClone is Event)
[/actionscript]

[result]
ArgumentError: Error #1063: Argument count mismatch on flash.events::Event(). Expected 1, got 0.
at flash.utils::ByteArray/readObject()
at mx.utils::ObjectUtil$/copy()
at Untitled_fla::MainTimeline/frame1()
[/result]

As noted by Nutrox, "All constructor parameters need a default value. You can't pass values directly to an object's constructor when it is restored from serialised data because Flash creates an instance of the object automatically before calling the object's readExternal() method."




What are your thoughts? I'm interested in striking a conversation about this.

0 comments: