0

我需要在 Adob​​e Air 中创建 XML 日志文件。我的第一个想法是使用某种自动序列化。我找到了 FlexXB 库。我创建了简单的记录器,并以下列方式用注释标记了类

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;

            }

}

我正在尝试序列化单个对象:

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() );

    }
}

现在,序列化产生一个错误: TypeError: Error #1009: Cannot access a property or method of a null object reference。在 com.googlecode.flexxb.core::SerializationCore/serialize()

当然,我可以一个一个地序列化集合中的所有对象,但我认为这是一个坏主意。

4

1 回答 1

0

这是我的问题的答案,由 FlexXB 工具的创建者提供

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

于 2012-04-26T13:36:03.570 回答