1 Attachment(s)
problem with array scope, need your help badly!!!!
I have worked on this a whole day, I want to make a flash navigation which get data from a xml file. now it's almost finished, but there's a problem with array scope that makes me unable to open a url ? have tried to mark the code red where it is concerning to the problem, and uploaded the fla and xml file. I am really looking forward to your help.
this is the AS:
_global.myTxt = new Array();
_global.myUrl = new Array();
_global.news_array = new Array();
var starXml = new XML();
starXml.load("star3.xml");
starXml.ignoreWhite = true;
System.useCodepage;
starXml.onLoad = function(success) {
if (success) {
trace("star.xml is loaded");
fetchTxt();
//this is the function used to get data form xml and make the btn mc. } else {
trace("star.xml isn't loaded");
}
};
//------------------------got XML date and put it in a array------------
function fetchTxt() {
for (i=0; i<starXml.firstChild.childNodes.length; i++) {
myTxt[i] = starXml.childNodes[0].childNodes[i].attributes;
}
trace("myTxt's length is "+myTxt.length);
//----------------put xml data into news_arry-----------------
for (i=0; i<starXml.firstChild.childNodes.length; i++) {
news_array[i] = myTxt[i].thename;
myUrl[i] = myTxt[i].theurl;//the theurl is the variable in xml file store the url trace("the theurl in xml is "+myUrl[i]);//it trace the right url here, but it is undifined late.
//trace("xml data is "+myTxt[i].thename);
//trace("news_array[i] is "+news_array[i]);
}
//--------------------make btns----------------
this.createEmptyMovieClip("newBtn", 100);
newBtn._x = 0;
newBtn._y = 5;
for (i=0; i<news_array.length; i++) {
this.attachMovie("btn", "newBtn"+i, 101+i);
eval("newBtn"+i).createTextField("btn_txt", 102, 0, 0, 10100, 18);
temp1 = eval("newBtn"+i);
temp1.btn_txt.text = news_array[i];
eval("newBtn"+i)._x = 0;
eval("newBtn"+i)._y = i*16+7;
//16是两个按钮_y的距离
eval("newBtn"+i)._alpha = 0;
eval("newBtn"+i).onRelease = function() {
trace("you clicked on "+myUrl[i]);//problem is here, it always trace "you clicked on undifined", why myUrl array is undifined here? and how can I use it??)
};
eval("newBtn"+i).onRollOver = function() {
this._alpha = 100;
};
eval("newBtn"+i).onRollOut = function() {
this._alpha = 0;
};
}
}