I’ve implemented this in com.emoten.core.data.JKDataObject in EmotenCore.swc
The [Transient] metadata is very important. ( keeps it from tying to infinitely clone itself )
I looked elsewhere and it seems that no-one has noticed that the [RemoteClass] metadata is required to reconstruct the class from its AMF-serialized state.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [Transient] /** * Creates a Clone of this class. * <p> * In order for your returned class to be typed correctly you must put the following * above "public class" * * <code> * [RemoteClass(alias="com.emoten.core.data.JKDataObject")] * </code> * * Replacing "com.emoten.core.data.JKDataObject" with your class's FQN. * * @return A new copy of your class. */ public function clone():* { var ba:ByteArray = new ByteArray(); ba.writeObject( this ); ba.position = 0; return ba.readObject(); } |
1 2 | [RemoteClass(alias="com.emoten.core.data.JKDataObject")] public class JKDataObject extends JKObject implements Cloneable |
UPDATE: Krilnon over at Kirupa made a good point I forgot to cover. The restrictions are that of the AMF specification. You cannot pass things like DisplayObjects and you cannot have required constructor arguments. If you don’t have those, your cool. The clone() functionality is only really intended for data models.
http://www.kirupa.com/forum/showpost.php?p=2489122&postcount=597
I designed a pure ActionScript event method following a similar API of JKEvent. In most circumstances it just barely beats out the speed of the native EventDispatcher but EventDispatcher is left in the dust when you start timing the whole event lifecycle: “connect, dispatch, disconnect, dispatch”.
Cons: You don’t get priority
Pros: You get Silent Events, Argument Events, Remove All(event connections) from Observer, Remove All(event connections) from Sender. Its fast.
How it works: Its built using Dictionaries and LinkedLists. Turned out pretty good since I wrote it last week and never tried to actually run it until now.
I recorded a variance of 0.5%+/-.
I licensed EmotenCore under LGPL and it is currently distributed as a compiled library.
Here is the License: License Here is the SWC: EmotenCore.swc Here is the docs: Emoten Core Docs
I’ve built this methodology for allowing the easy design and implementation of sequential bi-directional data translation using the InputFlowConnector / InputFlowTerminator interface model.
I’ve uploaded the example here: http://labs.emoten.com/projects/Juki/JKAbstractTranslatorLink/TranslatorTunnelTest.html
Note: The Easy User Input Translator does not understand AM/PM.
My first reference implementation is using the class JKTranslatorTunnel as a two-way binding mechanism with translation. Essentially it makes a 2-3 line implementation to bind your Model object to some sort of View with translation. My example is a case where the Model contains a integer property representing Military time and the view displays Standard time. I’ve also attached a user-input translator that converts shorthand input to Standard time. This comes in handy so we can translate shorthand to standard then pass the standard to the translator that will translate that into military time and update the model. At the same time it will also format the View.
The reference implementation in Flex looks like this. “in1″, “in2″ are both TextInput UIControls. JKAbstractTranslatorLink is a LinkedListEntry. To add many items into the translation link just keep on populating the “.next” or “output”.
Emoten Core Docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <fx:Script> <![CDATA[ import com.emoten.core.data.translators.JKEasyUserTimeInputTanslatorLink; import com.emoten.core.data.LinkedList; import com.emoten.core.data.JKAbstractTranslatorLink; import com.emoten.core.data.translators.JKMilitaryTimeTranslatorLink; import com.emoten.core.data.JKTranslatorTunnel; protected var _tunnel:JKTranslatorTunnel; public function onCompleteEvent( event:*=null ):void { var ls:JKAbstractTranslatorLink = new JKMilitaryTimeTranslatorLink(); ls.output( DirectionEnum.FORWARD, new JKEasyUserTimeInputTanslatorLink() ); _tunnel = new JKTranslatorTunnel( this.in1, "text", this.in2, "text", ls ); } ]]> </fx:Script> |
I found this link from a HOW-TO I made a long time ago that used to be linked from the old blog.