How to make an object serialize as a child node of an XmlElement ?

18 views
Skip to first unread message

Ranhiru

unread,
May 23, 2011, 5:00:34 AM5/23/11
to FxWorks
Perhaps the title is not very clear, sorry if it is. I'll try to
explain my situation.

I have a propertyValue among other properties in a class.

private var _propertyValue:Object;

[XmlElement(order="1")]
[Bindable]
public function get propertyValue():Object
{
return _propertyValue;
}


propertyValue will always be a IFill -> which is either SolidColor or
LinearGradient.

When I serialize this object for SolidColor, the object is serialized
to

<propertyValue color="13434726" alpha="1"/>

and for LinearGradient

<propertyValue rotation="90">
<entries>
<GradientEntry alpha="0.5" color="16711680"
ratio="0.30980392156862746"/>
<GradientEntry alpha="1" color="0" ratio="1"/>
</entries>
</propertyValue>


What I would actually want to do is, the SolidColor and LinearGradient
to be child nodes of propertyValue, so they would look like

<propertyValue>
<SolidColor color="13434726" alpha="1"/>
</propertyValue>


AND
<propertyValue>
<LinearGradient rotation="90">
<entries>
<GradientEntry alpha="0.5" color="16711680"
ratio="0.30980392156862746"/>
<GradientEntry alpha="1" color="0" ratio="1"/>
</entries>
</LinearGradient >
</propertyValue>

Any insight on how this would be possible?

Alexutz

unread,
May 23, 2011, 5:07:43 AM5/23/11
to FxWorks
Hi Ranhiru,

You should try virtual paths: http://code.google.com/p/flexxb/wiki/Samples2x#3._Using_virtual_paths

Can't try it now unfortunately but this piece of code should do the
job:

[XmlElement(order="1", alias="property/*")]
[Bindable]
public function get propertyValue():Object
{
return _propertyValue;

}

Let me know how it works,
Alex

Ranhiru

unread,
May 23, 2011, 5:31:57 AM5/23/11
to FxWorks
Hello Thanx a lot for quick reply Alex.

However I am getting a "Variable Untitled is undefined" error.

The stack trace if it is useful is shown below

ReferenceError: Error #1065: Variable Untitled is not defined.

at global/flash.utils::getDefinitionByName()
at mx.utils::DescribeTypeCache$/describeType()[E:\dev\4.0.0\frameworks
\projects\framework\src\mx\utils\DescribeTypeCache.as:106]
at DescriptorStore/put()
at DescriptorStore/getDefinition()
at DescriptorStore/getDescriptor()
at com.googlecode.flexxb.xml::XmlDescriptionContext/getXmlName()
at com.googlecode.flexxb.xml.serializer::XmlElementSerializer/
serializeObject()
at XmlMemberSerializer/serialize()
at com.googlecode.flexxb.core::SerializationCore/doSerialize()
at com.googlecode.flexxb.core::SerializationCore/serialize()
at com.googlecode.flexxb.xml.serializer::XmlArraySerializer/
serializeObject()
at XmlMemberSerializer/serialize()
at com.googlecode.flexxb.core::SerializationCore/doSerialize()
at com.googlecode.flexxb.core::SerializationCore/serialize()
at FlexXBCore/serialize()
at com.googlecode.flexxb::FlexXBEngine/serialize()

Ranhiru

unread,
May 23, 2011, 6:08:38 AM5/23/11
to FxWorks
Thanx a lot Alex :)
The code you gave actually worked and the mistake was on my side.

Thanx again :)

Ranhiru

unread,
May 23, 2011, 6:11:51 AM5/23/11
to FxWorks
P.S : Not to sound rude but the Virtual Path here was a life saver, so
it would be awesome to have some more detailed information about it in
the docs. For an example, what does * stands for etc etc.
Message has been deleted

Alexutz

unread,
May 23, 2011, 6:59:55 AM5/23/11
to FxWorks
True, true. I'll update the documentation to better explain this
feature.
> > > > > Any insight on how this would be possible?- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages