在Adobe Air中创建XML日志需要一些帮助

时间:2012-04-09 09:56:46

标签: actionscript-3 flex xml-serialization flex4.5

我需要在Adobe 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:错误#1009:无法访问空对象引用的属性或方法。     在com.googlecode.flexxb.core :: SerializationCore / serialize()

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

1 个答案:

答案 0 :(得分:0)

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

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