开发者

dict[obj] pulling wrong info at 35-36 xml node why?

I'm not sure how to explain this, but why isn't this code pulling the correct image and icon file? It continues to pull the wrong info at the line 35, which makes all other data one node behind. Even when I delete the three locations below, it still gets the xml wrong. Why would it be doing this?

I verified the xml data and made sure all the files were in the correct folder.

For example, this is a result from a trace:

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://w开发者_开发百科ww.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

Here is my xml at lines 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>

Here is my flex code:

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


the object class stores the value hashed by the toString() property of the key. So if two key renders as the same string the values will collide.

Use Dictionary instead.

here some more info: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Dictionary.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜