Search code examples
actionscript-3apache-flexxml-serializationflex4.5

Need some help in creating XML log in Adobe Air


I need to create XML log file in Adobe Air. My first thought was to use some kind of automated serialization. And I've found FlexXB library. I've created simple logger and marked the class with annotations in the following way

package loggingTools
{

    [XmlClass]
    [ConstructorArg(reference="timeStamp")]
    [ConstructorArg(reference="item")]
    [ConstructorArg(reference="action")]
    [ConstructorArg(reference="arguments")]
    [ConstructorArg(reference="success")]
    [Bindable]
    public class MessageAction
    {
    [XmlAttribute()]
    public var timeStamp:Date;

            [XmlAttribute()]
            public var item:String;

            [XmlAttribute()]
            public var action:String;

            [XmlAttribute()]
            public var arguments:String;

            [XmlAttribute()]
            public var success:Boolean;

            public function MessageAction(timeStamp:Date, item:String, action:String, arguments:String, success:Boolean) {
                    this.timeStamp = timeStamp;
                    this.item = item;
                    this.action = action;
                    this.arguments = arguments;
                    this.success = success;

            }

}

I'm trying to serialize the single object:

public class PlainXMLLogger
{
    //private static var isStarted:Boolean;

    private var logFile:XML;

            [XmlArray(alias = "Log", type="loggingTools.MessageAction")]
            [ArrayElementType("loggingTools.MessageAction")]
    public var messages:Array;

    public function addMessageAction(item:String, action:String, arguments:String, success:Boolean):void {
        var newMessageAction:MessageAction;
        newMessageAction = new MessageAction(new Date(), item, action, arguments, success);
        messages.push(newMessageAction);

    }

public function close():void {

        var logXML:XML = FlexXBEngine.instance.serialize(messages);

        trace(">> XML LOG ");
        trace(logXML.toString() );

    }
}

Now, serialization produces an error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.googlecode.flexxb.core::SerializationCore/serialize()

Sure, I can serialize all objects in collection one-by-one, but I consider, that this is a bad idea.


Solution

  • Here is the answer on my question, provided by creators of FlexXB tool

    https://groups.google.com/forum/?hl=ru&fromgroups#!topic/flexxb/g912jkxwldE