2010-02-27 29 views
0

我不知道如何解释这一点,但为什么不是这个代码拉正确的图像和图标文件?它继续在第35行提取错误的信息,这使得所有其他数据落后于一个节点。即使我删除下面的三个位置,它仍然会导致xml错误。为什么会这样做?dict [obj]在35-36 xml节点处拉错信息为什么?

我验证了xml数据并确保所有文件都在正确的文件夹中。

例如,这是从跟踪结果:

pm#: 35 xmlnodename: Causey's Pharmacy iconFL: http://www.mysite.com/folder1/folder2/media/marker.png imgFL: http://www.mysite.com/folder1/folder2/media/century21_img.swf 
pm#: 36 xmlnodename: Century 21 Property Shoppe iconFL: http://www.mysite.com/folder1/folder2/media/century21_icon.gif imgFL: http://www.mysite.com/folder1/folder2/media/century21_img.swf 
pm#: 37 xmlnodename: Century 21 Property Shoppe iconFL: http://www.mysite.com/folder1/folder2/media/century21_icon.gif imgFL: http://www.mysite.com/folder1/folder2/media/type1.swf 

这是我在XML行34-36

<location> 
    <name>Bobby&apos;s Pharmacy</name> 
    <street>123 Steet St.</street> 
    <city>SomeCity</city> 
    <state>ZZ</state> 
    <zip>12345</zip> 
    <lat>45.7520099</lat> 
    <long>-80.0816701</long> 
    <iconFile>marker.png</iconFile> 
    <imageFile>type1.swf</imageFile> 
    <motion>no</motion> 
    <featured>no</featured> 
    <category>none</category> 
    </location> 
    <location> 
    <name>Century 21 Property Shoppe</name> 
    <street>456 SomeOther St</street> 
    <city>SomeCity</city> 
    <state>ZZ</state> 
    <zip>12345</zip> 
    <lat>45.5683603</lat> 
    <long>-80.483271</long> 
    <iconFile>century21_icon.gif</iconFile> 
    <imageFile>century21_img.swf</imageFile> 
    <motion>no</motion> 
    <featured>yes</featured> 
    <category>none</category> 
    </location> 
    <location> 
    <name>Century 21 Property Shoppe</name> 
    <street>none</street> 
    <city>none</city> 
    <state>none</state> 
    <zip>none</zip> 
    <lat>45.4949689</lat> 
    <long>-80.6597955</long> 
    <iconFile>century21_icon.gif</iconFile> 
    <imageFile>century21_img.swf</imageFile> 
    <motion>no</motion> 
    <featured>yes</featured> 
    <category>none</category> 
    </location> 

这里是我的Flex代码:

private var mediaLoc:String = "http://www.mysite.com/folder1/folder2/media/"; 

    public function addMarkers():void 
    { 
     var dict:Object = new Object(); 
     var i:Number = 0; 
     var e:Number = locXML..location.length()+1; 
     trace("add markers: " + locXML..location.length()); 
     for(i;i<e;i++){ 

     if (locXML.location.name[i.toString()]== "mapLogo"){ 
      trace(i + " logo"); 
      //get lat and long from xml 
      dict["locPointMarker_lat" + i.toString()] = locXML.location.lat[i.toString()]; 
      dict["locPointMarker_long" + i.toString()] = locXML.location.long[i.toString()]; 
      //get iconfile name from xml and append it to mediaLoc--filepath 
      dict["iconFileLink" + i.toString()] = mediaLoc + locXML.location.iconFile[i.toString()]; 
      //create a new url request using the dict["iconFileLink" + i.toString()] filepath 
      dict["iconFileReq" + i.toString()] = new URLRequest(dict["iconFileLink"+i.toString()]); 
      //create a new pointmarker for the map 
      dict["locPointMarker"+i.toString()] = new PointMarker(); 
      //apply buttonmode and handcursor to the new pointmarker 
      dict["locPointMarker"+i.toString()].buttonMode = dict["locPointMarker"+i.toString()].useHandCursor = true; 
      //create a loader to load the icon file 
      dict["icon"+i.toString()] = new Loader(); 
      //load the icon file 
      dict["icon"+i.toString()].load(dict["iconFileReq"+i.toString()], context); 
      //put the marker on the map 
      _map.putMarker(new Location(locXML.location.lat[i.toString()], locXML.location.long[i.toString()]), dict["locPointMarker"+i.toString()]); 
      trace("pm#: " + i + " xmlnodename: " + locXML.location.name[i.toString()] + " iconFL: " + dict["iconFileLink" + i.toString()] + " imgFL: " + dict["imageFileLink" + i.toString()]); 
      dict["locPointMarker"+i.toString()].mouseChildren=false;    
     }else{ 
      //the following else does the same thing except it also adds the image file 
      dict["locPointMarker_lat" + i.toString()] = locXML.location.lat[i.toString()]; 
      dict["locPointMarker_long" + i.toString()] = locXML.location.long[i.toString()]; 
      dict["iconFileLink" + i.toString()] = mediaLoc + locXML.location.iconFile[i.toString()]; 
      dict["iconFileReq" + i.toString()] = new URLRequest(dict["iconFileLink"+i.toString()]); 
      dict["locPointMarker"+i.toString()] = new PointMarker(); 
      dict["locPointMarker"+i.toString()].buttonMode = dict["locPointMarker"+i.toString()].useHandCursor = true; 
      dict["icon"+i.toString()] = new Loader(); 
      dict["icon"+i.toString()].load(dict["iconFileReq"+i.toString()], context); 
      dict["icon"+i.toString()].x = -iconHeight/2; 
      dict["icon"+i.toString()].y = -iconWidth/2; 
      _map.putMarker(new Location(locXML.location.lat[i.toString()], locXML.location.long[i.toString()]), dict["locPointMarker"+i.toString()]); 
      trace("pm#: " + i + " xmlnodename: " + locXML.location.name[i.toString()] + " iconFL: " + dict["iconFileLink" + i.toString()] + " imgFL: " + dict["imageFileLink" + i.toString()]);    
      dict["locPointMarker"+i.toString()].mouseChildren=false; 
     } 
     } 
     } 

回答

0

对象类存储由该键的toString()属性散列的值。因此,如果两个键呈现为相同的字符串,则这些值将发生冲突。

使用字典来代替。

这里一些更多的信息:http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Dictionary.html

+0

我用字典,并从XML删除所有重复......同样的错误发生的情况。有没有更好的方法来创建类似于我以上所做的变量?我还需要能够更改子索引,但不知道如何访问字典或obj类的属性。 – Phil 2010-02-27 19:26:22