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'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;
}
}
}
我用字典,並從XML刪除所有重複......同樣的錯誤發生的情況。有沒有更好的方法來創建類似於我以上所做的變量?我還需要能夠更改子索引,但不知道如何訪問字典或obj類的屬性。 – Phil 2010-02-27 19:26:22