我有一个TileList,我加载了一个PHP脚本,它返回一个动态生成的xml,所以我可以加载TileList及其所需的图像和标签。
现在,我想点击TileList的一个项目并检索它的Label,这样我就可以将它发送到另一个PHP脚本,该脚本使用Label的字符串来进行搜索查询,这样我就可以将纬度和经度加载到地图到该项目的位置。
我一直试图追踪它,但它不行。
var path:String = "http://localhost/entretenimiento.php";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
xmlLoader.load(new URLRequest(path));
function onLoadComplete(e:Event):void {
System.disposeXML(xmlData);
var xmlData:XML = new XML(e.target.data);
//trace(xmlData);
for (var i:int=0; i<xmlData.e_nombre.length(); i++)
{
myTileList.addItem({label:xmlData.e_nombre[i], source:xmlData.e_imagen[i]});
//trace(xmlData.e_nombre[i]);
}
var display;
myTileList.addEventListener(Event.CHANGE, listListener);
myTileList.selectedIndex = 0;
function listListener(event:Event):void {
display.source = myTileList.selectedItem.label;
trace(display.source);
trace("working");
}
}
我需要帮助,我不知道如何从点击TileList的项目中检索标签。
我正在使用Flash CS5。
答案 0 :(得分:1)
// this should live somewhere in your code:
var path:String = "http://localhost/entretenimiento.php";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onComplete);
xmlLoader.load( new URLRequest( path ));
private function onComplete(e:Event):void
{
// XML works just fine as a data provider, you don't need the loop.
myTileList.dataProvider = new DataProvider(new XML(e.target.data));
// You can assign which properties of the xml the list uses.
myTileList.sourceField = "e_imagen";
myTileList.labelField = "e_nombre";
// I'm assuming that the goal is to have the user select an item,
// so we'll register to listen for a click.
myTileList.addEventListener( MouseEvent.CLICK, listListener );
}
private function listListener(e:Event):void
{
/*
Because we're listening for a click, and the listener is registered to the list
make sure that what we've clicked is an item (a CellRenderer) and not the
background or something.
*/
if ( getDefinitionByName(getQualifiedClassName(e.target)) == CellRenderer )
{
// You can call your other web service from here.
// The "target" is a CellRenderer, and its data is an XML node.
trace(e.target.data.label);
}
}
答案 1 :(得分:0)
好的,好吧......
这很简单,午睡后我坐下来尝试了这个,它给了我想要的东西。
var path:String = "http://localhost/entretenimiento.php";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
xmlLoader.load(new URLRequest(path));
function onLoadComplete(e:Event):void {
System.disposeXML(xmlData);
var xmlData:XML = new XML(e.target.data);
//trace(xmlData);
for (var i:int=0; i<xmlData.e_nombre.length(); i++)
{
myTileList.addItem({label:xmlData.e_nombre[i], source:xmlData.e_imagen[i]});
//trace(xmlData.e_nombre[i]);
}
myTileList.addEventListener(Event.CHANGE, listListener);
myTileList.selectedIndex = 0;
function listListener(event:Event):void {
trace(myTileList.selectedItem.label);
}
}