Adobe AIR 3.4将XML数据保存/写入iOS

时间:2013-04-05 17:31:00

标签: ios actionscript-3 air adobe

我正在尝试使用适用于iOS的AIR 3.4将XML数据保存到iPad 4,并且实际上无法判断这是否有效。显然没有事件被解雇。非常感谢任何帮助。

    private function saveData(e:MouseEvent):void {




        var name:String = AssetManager.SAVE_ANNOTATIONS_NAME            
        var file:File = new File()              
        file = File.applicationStorageDirectory.resolvePath(name + "xml");
        var xml:XML = _canvas.getObjectData(FormatType.DEGRAFA);            
        var fileStream:FileStream = new FileStream();
        fileStream.open(file, FileMode.WRITE);
        fileStream.writeUTF(xml.toString());


        fileStream.addEventListener(ProgressEvent.PROGRESS, onFileStream);
        fileStream.addEventListener(Event.ACTIVATE, onFileStream);
        fileStream.addEventListener(Event.OPEN, onFileStream);
        fileStream.addEventListener(Event.DEACTIVATE, onFileStream);
        fileStream.addEventListener(IOErrorEvent.IO_ERROR, onFileStream);
        fileStream.addEventListener(Event.COMPLETE, onFileStream);



    }

    protected function onFileStream(event:Event):void
    {
        trace('filestream event was ' + event)
        fileStream.close();


    }   

3 个答案:

答案 0 :(得分:3)

我似乎已经修好了这个:

    private function saveFile(event:MouseEvent):void
    {  
        var xml:XML = _canvas.getObjectData(FormatType.DEGRAFA);
        trace('xml is ' + xml.toXMLString())
        var file:File = File.documentsDirectory.resolvePath("annotations.xml");         
        var fileStream:FileStream = new FileStream();  

        fileStream.openAsync(file, FileMode.WRITE);  
        fileStream.writeUTFBytes(xml.toXMLString()); 
        fileStream.addEventListener(Event.CLOSE, fileClosed);  
        fileStream.close();  

        function fileClosed(event:Event):void { 

            trace("File Saved");  

        }        
    }  

答案 1 :(得分:0)

您正在编写之前添加侦听器。正确的顺序应该是:

    var fileStream:FileStream = new FileStream();

//这里的所有听众

    fileStream.open(file, FileMode.WRITE);
    fileStream.writeUTF(xml.toString());

答案 2 :(得分:0)

您必须记下用于打开文件流的命令。如果使用filestream.openAsync,则文件流将异步打开,这意味着您必须等待文件流对象上的Event.OPEN事件。如果使用filestream.open,则可以立即调用filestream对象上的函数,而无需等待OPEN事件。对我来说,跳转到ActionScript及其异步性质需要一些时间来习惯。