« Flex Builder 2 free for students and educators
» FABridge: Warn on flex application exit

ActionScript, Flex 2

[Transient] metadata Tag

Virgil Cristea | 25.10.07 | 2 Comments

One interesting that I have found is the [Transient] metadata . What it does?

It instructs Flex not to serialize the object member (variable/function) when you do a serialize/deserialize of an object.

Here is a quick more in detail code

public class Test
{
  private var x: int;
  private var y: int;
 
  public function get xval():int
  {
    return x*x;
  }
 
  public function set xval(value:int)
  {
     x= x*y;
  }
 
  public function set yval(value:int)
  {
     y=value + 1;
  }
}

If you try to serialize and deserialize an instance of this class you would see that the values for x,y are different before and after. Why?

Well it seems that in the deserialization process all the values are extracted (x,y,xval and yval) and the getters/setters are executed. How to solve this problem? Simpl: use the [Transient] tag:

[Transient]
public function get xval():int

When the object will be serialized the value for the xval will not be present and the getter/setter will not be executed.

The [Transient] metadata tag is not very well documented in Flex 2 or 2.0.1. If you look in some of the LiveCycle Data Services documentation you can see mentions of it, but there isn’t a dedicated page on the subject. In the beta Flex 3 documentation, [Transient] is finally explained. There is also some documentation gathered on The Flex Non-Docs weblog.

The [Transient] metadata tag can be used for classes that need to be on the server but also for other classes (when doing deep copies of them - I will write another post about object deep copy later - Here).

So the summary:

using [Transient] on a property removes that property from the AMF packet during serialization

Thanks to Darron Schall where I first saw the [Transient] metadata tag

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , ,

This post was written by Virgil Cristea

Views: 995

related

2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« Flex Builder 2 free for students and educators
» FABridge: Warn on flex application exit