dict [obj]在35-36 xml节点拉错信息为什么?

时间:2010-02-27 06:04:30

标签: actionscript-3 arrays dictionary flex4

我不知道如何解释这个,但为什么这段代码没有拉出正确的图像和图标文件?它继续在第35行提取错误的信息,这使得所有其他数据成为一个节点。即使我删除下面的三个位置,它仍然会得到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

这是我在第34-36行的xml

  <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>

这是我的灵活代码:

    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;
        }
        }
        }

1 个答案:

答案 0 :(得分:0)

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

改用词典。

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