请帮我。
我正在使用离线地图,并从 XML 读取数据。我将数据放入 DataGrid 中,当我从数据网格中选择项目时,我在舞台中添加子项并为数据创建一个影片剪辑(一次可能有多个子项),但是当我从数据网格中选择另一个项时,新的子项添加了但是旧的没有删除。
这是我的代码:
familyGrid.addEventListener(Event.CHANGE, get_data2);
function get_data2(event:Event):void {
//get the selected item's name and search in another xml file
//for the points that have the same name
nameFamilyText.text= familyGrid.selectedItem.Latin;
var pattern_pID2:RegExp;
current_pID2 = [];
pattern_pID2 = new RegExp(nameFamilyText.text);
for (var n:int = 0; n<all_pID2.length; n++)
{
if ((pattern_pID2.test(all_pID2[n].fLatinName) || nameFamilyText.text=="") )
{
current_pID2.push(all_pID2[n]);
var fxnList:XMLList = pID_data2.marker.(@LatinName == nameFamilyText.text);
for each (var xnNode:XML in fxnList)
fButtonName.text= xnNode.@LatinName.toXMLString()
//create marker in the satge which have a n image of offline map
// i need to remove the old one before add a new one
var newString:String = ("id_"+all_pID2[n].id);
var markLoader:Loader = new Loader();
var myMark:String= ("T copy.png");
markLoader.load(new URLRequest (myMark));
markLoader.x=this[newString].x-8;
markLoader.y=this[newString].y-20;
addChild(markLoader);
markLoader.addEventListener(MouseEvent.CLICK, getToolTip);
function getToolTip(e:MouseEvent) {
var flabel:TextField = new TextField();
flabel.width=150;
flabel.height=20;
flabel.border=true;
flabel.background=true;
flabel.autoSize=TextFieldAutoSize.RIGHT;
flabel.text=xnNode.@Species_name.toXMLString();
flabel.x=markLoader.x-30;
flabel.y=markLoader.y-20;
addChild(flabel);
flabel.addEventListener(MouseEvent.CLICK, fShowData);
function fShowData(e:MouseEvent) {
///create movieclip for data
var fmc:MovieClip = new MovieClip();
fmc.graphics.beginFill(0x000000, .75);
fmc.graphics.drawRect(60, 90, 700, 500);
fmc.graphics.endFill();
fmc.x = 80;
fmc.y = 60;
addChild(fmc);
}}}
updateList2();
}}