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> |
JIRA SDK-16960
Java explanation of Late-Binding
The Issue
Subclassing has one purpose, to further specialize. If I want to extend my ‘FarmAnimal’ class and call it ‘Chicken’ that is specialization. If I extend ‘Real-Estate’ with ‘Condo’, that is specialization. So, what if I want to further restrict the acceptable properties of my sub-class? Override polymorphism allows us to redefine a inherited method from our super-class but doesn’t allow us to sub-specialize the method arguments(parameters) and return type. Why is this? If the specialized arguments and return type are fully type-safe against the requirements of the super-class then what is the problem?
The Example
Say my class ‘FarmAnimal’ has a method.
public clone():FarmAnimal {}
Now, I have a class ‘Chicken’ extends ‘FarmAnimal’. ‘Chicken’ has methods associated with it that do not exist in ‘FarmAnimal’. However, when I call chicken.clone() I still get a class instance typed FarmAnimal. Which is correct, it returns a Chicken object typed as FarmAnimal because override polymorphism says so. Now, every time I want to use methods special to Chicken. I have to retype the object as chicken.
chik:Chicken = chicken.clone() as Chicken;
This is ok. Now, what if clone() has a argument.
public FarmAnimal clone(mate FarmAnimal) {}
Thats cool but a Chicken can’t mate with a Pig so we’ve got to do something about this. Override polymorphism says we can’t change the arguments. Wouldn’t it be awesome if we could just re-define clone() as
public clone(mate:Chicken):Chicken {}
Well we can’t. What are our options? Interfaces have the same restrictions. We usually end up abandoning polymorphism completely in order to accomplish the task at hand or creating manual type checking on every override to prevent the wrong type of object being passed. All arguments aside, Chicken is a FarmAnimal so it is theoretically type-safe against the super’s version of makeSpawn. I don’t understand why the rules of polymorphism can’t be adapted to support this type of behavior.
UPDATE: Method Overloading as defined by Late-Binding in Java does partially do what I ask but does not hit the nail on the head because, ultimately, the original version is left intact whereas I would want to disallow it completely and would not be compatible when accessing typed as a Interface.
Any ideas? Hit me up on Twitter.
Comptibility: 3.0+
You can extend CSS’s basic functionality with Custom Data Types by adding your own code to line: 7808 ( function getStyle(styleProp:String)* ) of mx.core.UIComponent. I recommend doing this by copying paste the original UIComponent class, from your destination version of the Flex framework, into your project under the same package name. This will allow your version to override the compiled library version.
I’ve extended CSS with a custom protocol for a library engine I’ve dubbed ‘Fuze’ for the moment. The implementation of the protocol in the CSS file looks like this:
1 | upSkin : "Fuze(splashelements>ButtonSi)"; |
The reason why implementing the override on the UIComponent class is to interject some business logic to your protocol. In my example, the FuzeService takes the protocol and returns the proper library item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public function getStyle(styleProp:String):* { var ret:* = StyleManager.inheritingStyles[styleProp] ? _inheritingStyles[styleProp] : _nonInheritingStyles[styleProp]; if ( ret is String && (ret as String).substr(0,5 ).toLowerCase() == "fuze(" ) { if (FuzeService.hasLoaded( ret )) { // Cache it here. var clz:Class = FuzeService.getDefinitionByURI( ret ); if ( StyleManager.inheritingStyles[styleProp] ) _inheritingStyles[styleProp] = clz; else _nonInheritingStyles[styleProp] = clz return clz; } else { throw new IllegalArgumentException("The Requested Fuze Dynamic Skin Library Has Not Yet Loaded, Please check your code to make sure the library has loaded before you initialize any mx.* components using the CSS Fuze extension "); } } return ret; } |
I am a big fan of Signals/Slots and the Messaging Paradigm used by Cocoa. Since neither can really be implemented flawlessly in AS3(without some major potential performance issues down the road). I came up with a Hybrid Event Pattern solution I call the “Juki Event Pattern(JEP)”. Here is a PDF document outlining the pattern.
The major difference between JEP and the one adopted by Java/Flash is the fact that the events are exposed as public getter functions. This leads to whole new worlds of interface-required events. However, the pattern maintains full backwards compatibility with the built-in event pattern. JEP is an extension of the basic event pattern and requires a IEventDispatcher for the purpose of carrying out the actual dispatching.
A simple interface is used to “connect” a listener function or event to another event. Yes, I said you can connect one event to another. Also because the events are exposed as a public getter you could essentially wrap another event from a asset class and expose it as your own.(think about that for a moment). I have provided three connection options: “connect”, “connectAsSilent”, and “connectAsPassThrough”. Respectfully the operations are basic connect: where the event object is passed to the listener, where nothing is passed to the listener, where all arguments of the dispatch() method are passed to the listener.
Full disconnect. As requested, I have provided the ability to disconnect from all listeners. I also maintain a list of the listeners in a soft-linked Dictionary object. This was also another request that I ended up finding useful for internal uses.
Dispatch log. I made a decision early on that my primary problem with the default event pattern is that there is no way to tell if any specific event has already dispatched. The problem here is sometimes a event only fires once. Say, If it represents a “download complete”. It fires once, if you fail to catch it, your screwed. Normally, I’d say, check your code try to catch it earlier. What if that wasn’t possible tho. I maintain a array of the last arguments passed to the event and if it has dispatched yet. Sadly, for memory purposes I have chosen not to capture dispatches outside of the JEP. I may implement this as a “use as your own performance risk” feature later.
I just wanted to make a quick point. If you ever find yourself requiring the ability to add a NON UIComponent/IUIComponent DisplayObject on the stage in Flex. You can simply use a SWFLoader instance because it does not force UIComponent/IUIComponent type checking.
Below is a example I setup to load Image data as a Image as Class but this could be anything, Sprite, MovieClip, etc.
1 2 3 4 5 | [Embed(source="images/myimage.jpg", mimeType="image/jpeg")] public var tileExample:Class; var loader3:SWFLoader = new SWFLoader(); loader3.addChild( new tileExample() ); loader3.y = 550; this.addChild( loader3 ); |

The new Styling Mechanism allows for a better control of shared Style Definition bases versus sharing the Proxy directly. The Style Definition will also signal all connected proxys of any changes. Style Proxies contain the local-only definition, including overrides and cache information for extended lookups. Changes can be “pushed” to the definition. The Proxies inherit automatically as parent/children in the DisplayList and can be turned off. The Master Style Dictionary can also load multiple CSS files. Expect tighter integration with the Theme Server for use with “groups” to define a fully inheritable solution for any desired use. There is also a new mechanism for “impact decisions” for the state of the DisplayObject. More later.