[英]How to load xml item one at a time as3
Flash AS3: Flash AS3:
Does anyone know how to load items one at a time instead of loading in loop at a normal process using AS3? 有谁知道如何一次加载一个项目,而不是使用AS3在正常过程中循环加载? I'm having problem with overwritten value.
我有覆盖价值的问题。
I couldn't make that work, it's always overwritten the last value.I tried to use the dictionary and though it will help to resolve my problem... 我无法完成这项工作,它总是会覆盖最后一个值。我尝试使用字典,尽管它可以帮助解决我的问题...
I want to be able for EACH button when I clicked it displays the visibility of my markers. 我希望能够在单击每个按钮时显示其标记的可见性。
private function handleMarkers(event:CustomEventCenter):void
{
// Get items info from custom dispatcher
var nom = event._name.nom;
...
var tabMarkerID:Array = new Array();
// Defined positions for button
var xPos = 20;
var yPos = 0;
// Store the right markerID into each index separated
if (event._name.markerID == '01') {
tabMarkerID[0] = event._name.markerID;
} else if (event._name.markerID == '05') {
tabMarkerID[1] = event._name.markerID;
}
// Create a dictionary
var dict:Dictionary = new Dictionary();
// Create arrondissement objects for 14 available markers
var arrond1:Object = new Object();
var arrond2:Object = new Object();
dict[arrond1] = tabMarkerID[0];
dict[arrond2] = tabMarkerID[1];
for (var i=0;i<2;i++)
{
pointRepere = new PointRepere();
for (var item:Object in dict)
{
if (dict[item] != undefined) {
pointRepere.name = String(dict[item]); // here the issue
pointRepere.x = xPos;
pointRepere.y = yPos;
yPos += i*20 + 40;
pointRepere.buttonMode = true;
addChild(pointRepere);
createMarkers(dict[item], nom);
pointRepere.addEventListener(MouseEvent.CLICK, handlePointClicked);
}
}
}
}
private function handlePointClicked(event:MouseEvent):void
{
trace("Name: "+event.target.name);
displayMarkerType(event.target.name);
}
private function displayMarkerType(id:String):void
{
for (var i=0; i< _marker.tabArrondMarker[id].markers.length; i++)
{
var marker:Marker = _marker.tabArrondMarker[id].markers[i];
(!marker.visible) ? marker.visible = true : marker.visible = false;
}
}
It seems like you'd want to lazy load your xml files - you'd need to construct a loop that runs based on an array of the items you want to load - here is an example of how you could do that: 似乎您想延迟加载xml文件-您需要构建一个基于要加载的项目数组运行的循环-这是如何执行此操作的示例:
private var Array:list;
private var int:count = 0;
private function init()void
{
list = {"one.xml","two.xml","three.xml"};
loadXML();
}
private function loadXML():void
{
//create and init your loader
var loader:URLLoader = new URLLoader(new URLRequest(list[count]));
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.load();
}
private function completeHandler(e:Event):void
{
//Logic here to handle the loaded xml
continueLoad();
}
private function ioErrorHandler(e:IOErrorEvent):void
{
//Logic here to handle the error
continueLoad();
}
private function continueLoad():void
{
if(count < list.length){
count++;
loadXML();
}else{
//Some logic here to do something else after all of your files have been loaded
}
}
I just this threw this together here so you may need to fix a thing or two but you see the gist - it's a loop that executes only after each individual file has been loaded as opposed to just throwing it all in a for loop and having it execute and subsequently grind and then crash. 我只是将其放在这里,所以您可能需要修复一两件事,但您会发现要点-这是一个循环,仅在加载每个文件后才执行,而不是将其全部放入for循环中并放入执行,然后研磨,然后崩溃。
Hope this helps! 希望这可以帮助!
You can load them all, and then reference them by their index. 您可以全部加载它们,然后通过它们的索引引用它们。 Like
喜欢
xmlData.YourChildNodeName[0]
Where the 0 is the index number. 其中0是索引号。 This will just pull back the first child node by that name.
这只会拉回该名称的第一个子节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.