Apr 14
The [Transient] and [Mixin] metadata tags
There are a couple useful metadata tags that are not particularly well documented in the Flex Livedocs that I have come across recently.
[Mixin]
The first is the [Mixin] metadata tag, which I saw a while back while reading about the RandomWalk component in the Flex docs for Creating Applications for Testing, but I never quite understood what it did until I came across this post by Adam Flater.
So, here is what it does: when you put the [Mixin] metadata just above your class definition and add a static init function to the class like so,
[Mixin]
public class Model
{
public static function init (systemManager : ISystemManager)
{
trace ("I get called first")
}
}
the static init function will be called as soon as your application loads (assuming this class is referenced somewhere in the app), much like static initialization blocks in Java, or static constructors in C#. This is useful if you have some code that you want to run before any of the other code in the class.
[Transient]
I just learned about this tag today from a comment by one the readers of this blog (thanks David).
The [Transient] tag is extremely useful for working with Value Objects because it allows you to tag properties that you do not want to send across the wire when the object is serialized.
For example,
package com.rxr.issuetracker.vo
{
import com.adobe.cairngorm.vo.IValueObject;
import mx.collections.ArrayCollection;
[Bindable]
[RemoteClass(alias="com.rxr.issuetracker.vo.Project")]
public class ProjectVO implements IValueObject
{
private var _issues : ArrayCollection = new ArrayCollection();
public var id : int;
public var user_id : int;
public var title : String;
[Transient]
public function get issues () : ArrayCollection
{
return _issues;
}
public function set issues ( value : Array ) : void
{
_issues= new ArrayCollection(value);
}
}
}
Now when you send this ProjectVO across the wire to Rails (or PHP, ColdFusion, Java, .NET, etc) the issues ArrayCollection will not be sent with it.
As always, let me know if you have any questions or if any of this is unclear or incorrect. Also, please let me know if you know about any other useful metadata tags that are not included in the list on livedocs.

April 14th, 2007 at 4:39 am
Wow, this is great stuff Derek! Thanks for sharing.
April 14th, 2007 at 8:45 pm
Thanks , this was really usefull info
cheers
Firdosh Tangri
April 25th, 2007 at 6:37 am
Very nice. Thanks for the info on [Transient] and thanks for the credit on the [Mixin] tag.
-
Adam Flater
Software Architect
effectiveUI
adam.flater@effectiveui.com
June 15th, 2007 at 12:05 am
[...] a previous post I discussed how you can use the [Mixin] metadata tag to create a static initialization in Flex. Here is another way to do pretty much the same [...]
June 15th, 2007 at 5:17 am
Thanks derek for the info. [Transient] metatag is really useful. Though I discovered [mixin] very recently somewhere else
February 1st, 2008 at 9:15 am
[...] http://flexonrails.net/?p=78 http://flexonrails.net/?p=66 [...]