dongni3854 2014-04-03 14:39
浏览 117

在AS3 Flash中编辑和保存XML

I have difficulty with this since this morning, so I finally decided to ask for your help.. I've tried many solutions but none works as I want. I want to load a XML file (local) and edit it and then save the results in the same file. The loading/reading isn't an issue, it works fine, but to save the file is very hard in as3.

(nb: I have an local serveur, so this isn't the problem)

Here's my best approach of the problem so far (found here):

save.php :

<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){ 
    $xml = $GLOBALS["HTTP_RAW_POST_DATA"]; 
    $file = fopen("http://localhost/cs_texte.xml","wt"); 
    fwrite($file, $xml); 
    fclose($file);
} 
?>

myAs3script.as :

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

// Loading XML -> works fine     
xmlLoader.load(new URLRequest("http://localhost/cs_texte.xml"));

//When loading complete          
function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    trace(xmlData); // Works fine 

    [.. Do some stuff on xml ..]

    var xmlResponse:XML;
    var xmlURLReq:URLRequest = new URLRequest("http://localhost/save.php");
    xmlURLReq.data = xmlData;
    xmlURLReq.contentType = "text/xml";
    xmlURLReq.method = URLRequestMethod.POST;
    var xmlSendLoad:URLLoader = new URLLoader();
    xmlSendLoad.addEventListener(Event.COMPLETE, completeHandler);
    xmlSendLoad.load(xmlURLReq);

    function completeHandler(evt:Event) {
        trace ('Save complete');
    }           
}

But it's not working, the xml file doesn't change at all, even if I try to empty it..

Any idea why ? (And do you know how to get php error in flash output console ? if there is any..)

Thansk for your help ! (And please be indulgent, this isn't my project initially..)

  • 写回答

1条回答 默认 最新

  • douma5954 2014-04-04 08:02
    关注

    Thanks to Andrey Popov I figured out the problem, it was just a problem of absolute url instead of a relative url.. So you need to give a relative address from your PHP file like that :

    <?php
    if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){ 
        $xml = $GLOBALS["HTTP_RAW_POST_DATA"]; 
        $file = fopen("cs_texte.xml","wt"); 
        fwrite($file, $xml); 
        fclose($file);
    } 
    ?>
    

    It was just that, but it gives me really hard time ! Thanks to help me figured out, hope that would help someone !

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用