Air As3 XML 编辑/保存

发布于 2024-10-01 00:55:41 字数 192 浏览 0 评论 0原文

我需要创建一个类来简化将动态/输入 TextField 文本保存到 XML 文件的过程。我已经将 XML 对象从 as3 保存到文件系统上的文件中,没有出现任何问题。基本上我需要的是一个通用类,可以给它一个 DisplayObject,以将其所有 TexField 设置为 XML 中的数据。我需要一种将 TextField 链接到其数据的方法。我用的是Air 2.0。

I need to make a class that simplifies saving dynamic/input TextField text to an XML file. I've got it saving the XML object from as3 to a file on the file system without problems. Basically what I need is a generic class that can be given a DisplayObject to have all of its TexField's set to the data in XML. I need a way of linking the TextField to its data. I'm using Air 2.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-10-08 00:55:41

我不确定我完全理解你的问题,但你可以尝试循环显示对象的所有子对象,检查文本字段,如果找到它们,请将它们写出到 XML。像这样的东西...

function writeChildTextFieldsToXML(xml:XML, container:DisplayObjectContainer):void {
    for (var i:int = 0; i < container.numChildren; i++) {
        var child:DisplayObject = container.getChildAt(i);
        if (child is TextField) {
            var text:String = TextField(child).text;
            // Write text to xml
        }
        if (child is DisplayObjectContainer) {
            // recursively inspect the child container for textfields
            writeChildTextFieldsToXML(xml, DisplayObjectContainer(child));
        }
    }
}

I'm not sure I totally understand your question but you could try looping through all the children of the display object, checking for textFields, and if you find them, write them out to XML. Something like this...

function writeChildTextFieldsToXML(xml:XML, container:DisplayObjectContainer):void {
    for (var i:int = 0; i < container.numChildren; i++) {
        var child:DisplayObject = container.getChildAt(i);
        if (child is TextField) {
            var text:String = TextField(child).text;
            // Write text to xml
        }
        if (child is DisplayObjectContainer) {
            // recursively inspect the child container for textfields
            writeChildTextFieldsToXML(xml, DisplayObjectContainer(child));
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文