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>

    运行,无错!

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

  • 相关阅读:
    CentOS7下搭建hadoop2.7.3完全分布式
    在linux命令行利用SecureCRT上传下载文件
    SPDY和HTTP
    哈希表的工作原理
    LVS(Linux Virtual Server)
    Discuz x3 UCenter实现同步登陆原理
    Goroutine(协程)为何能处理大并发?
    缓存与DB数据一致性问题解决的几个思路
    固态硬盘SSD与闪存(Flash Memory)
    堆和栈的区别(转过无数次的文章)
  • 原文地址:https://www.cnblogs.com/felixfang/p/1423351.html
Copyright © 2011-2022 走看看