zoukankan      html  css  js  c++  java
  • [Flex] flex读取xml格式数据的一个问题

    之前曾花过一段时间整过flex读取xml,以为这方面已经是轻车熟路了,没想到今天在上面在了个跟斗。

         先把代码写下:

    mxml:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
    <mx:Script>
     <![CDATA[
      import mx.collections.ArrayCollection;
         import mx.controls.Alert;
      
      [Bindable]
      private var picArr:ArrayCollection = new ArrayCollection();
     
      private function showPic():void
      {
       picArr = picRequest.lastResult.questions.choice;
       Alert.show(picArr.getItemAt(1).title);
      }
      
     ]]>
    </mx:Script>


    <mx:HTTPService id="picRequest" url="books.xml" result="showPic()"/>

     <mx:Button x="269" y="253" label="Button" click="picRequest.send()"/>

    </mx:Application>

    books.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <questions>
          <choice>
                <title>test xml</title>
          </choice>
    </questions>

    运行时却总是报错,错误代码为:

    TypeError: Error #1034: 强制转换类型失败:无法将 mx.utils::ObjectProxy@76dff71 转换为 mx.collections.ArrayCollection。

    把以前的代码拿出来对了半天都找不错,最后发现问题所在:当xml中只有一条<choice>记录时,就会报错。

    在原来的基础上又添了一条记录:

    <?xml version="1.0" encoding="utf-8"?>
    <questions>
          <choice>
                <title>test xml</title>
          </choice>
    </questions>

    <questions>
          <choice>
                <title>test xml again</title>
          </choice>
    </questions>

    运行,无错!

    跟本问题尚不清楚,高手知道的话请告诉在下,感激不尽!

  • 相关阅读:
    MySql存储引擎MyISAM和InnoDB的区别
    Nginx下载安装
    科目三考试训练大纲
    解决The current branch is not configured for pull No value for key branch.master.merge found in config
    java实现截取6个汉字字母数字
    如何将git上的代码迁移到Coding上
    Python抓取博客园首页文章列表(带分页)
    Python实现抓取CSDN博客首页文章列表
    Python实现抓取CSDN热门文章列表
    linux目录的操作
  • 原文地址:https://www.cnblogs.com/felixfang/p/1423351.html
Copyright © 2011-2022 走看看