-1

我是 flex 开发的新手,需要帮助。

我有一个 xml 文件,其中包含我想在用户更改任何内容时更新的数据,该文件保存在应用程序所在的本地程序文件中。

这是我读取 XML 文件的代码:

    <fx:Declarations>
    <s:HTTPService id="systemData" url="data/system.xml" method="POST"/>
</fx:Declarations>

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.rpc.events.ResultEvent;

        [Bindable]
        private var systemInfo:Object = new Object();

        private var interval:uint;

        [Bindable]
        private var xmlData:ArrayCollection = new ArrayCollection();

        private function viewMain(event:Event):void
        {

            mainWindow.visible = true;
            systemWindow.visible = false;
        }

        private function viewSystem(event:Event):void
        {

            mainWindow.visible = false;
            systemWindow.visible = true;


        }

        public function init():void
        {

            systemData.addEventListener(ResultEvent.RESULT, getXML);
            systemData.send();

            interval = setInterval(reloadXML, 1800000);

        }

        private function getXML(e:ResultEvent):void 
        {   

            systemInfo = systemData.lastResult.system;
            systemIP.text = systemInfo.systemip;
            systemPort.text = systemInfo.systemport;
            systemUsername.text = systemInfo.systemusername;
            systemPassword.text = systemInfo.systempassword;

        }
        private function reloadXML():void
        {
            systemData.send();
        }


    ]]>
</fx:Script>


<s:BorderContainer id="mainWindow" width="100%" height="100%" visible="false">
    <s:Button x="434" y="102" label="System Settings" click="viewSystem(event)"/>
    <s:Button x="468" y="147" label="Button" />

</s:BorderContainer>


<s:BorderContainer id="systemWindow" width="100%" height="100%" visible="true">
    <s:Panel width="800" height="600" horizontalCenter="0" title="System Settings"
             verticalCenter="0">
        <s:Label x="33" y="41" text="Server IP:"/>
        <s:Label x="33" y="66" text="Port:"/>
        <s:Label x="33" y="90" text="Username:"/>
        <s:Label x="33" y="115" text="Password:"/>
        <s:TextInput  x="182" y="31" width="250" id="systemIP"/>
        <s:TextInput  x="182" y="56" width="250" id="systemPort"/>
        <s:TextInput  x="182" y="80" width="250" id="systemUsername"/>
        <s:TextInput  x="182" y="105" width="250" id="systemPassword"/>
        <s:Button x="345" y="135" label="Save to XML" />
        <s:Button x="718" y="-26" label="Main" click="viewMain(event)"/>
    </s:Panel>
</s:BorderContainer>

XML 文件:

     <?xml version="1.0" encoding="utf-8" standalone="no"?>
     <system>
     <systemip>127.0.0.0</systemip>
     <systemport>80</systemport>
     <systemusername>rootu</systemusername>
     <systempassword>passu</systempassword>
     </system>

提前致谢

4

1 回答 1

0

要将更新的内容写回您的 xml 文件中,您需要将文件写回。我假设您的应用程序是 Adob​​e AIR 应用程序。您可以使用“文件”类来读取和写入内容。链接:http ://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html

于 2013-05-07T09:47:57.597 回答