NEED HELP ASAP, like by tomorrow morning! durrrr.
Yeah so like, this sux… I need to load a variable from a text file, search an array for the loaded variable, and output the result! EASY, so what’s UP?.. check it out:
_global.activeCity;
///////////////////////////
// Array serch function: //
///////////////////////////
Array.prototype.find = function(foundFuncOrSearch, notFoundReturnVal) {
if (typeof (foundFuncOrSearch) == "function") {
for (var i = 0; i<this.length; i++) {
if (foundFuncOrSearch(this*)) {
return this*;
}
}
return notFoundReturnVal;
} else {
for (var i = 0; i<this.length; i++) {
if (foundFuncOrSearch == this*) {
return this*;
}
}
return notFoundReturnVal;
}
};
/////////////////load the vars
// city.txt is as follows: activeCity=Auckland
/////////////////////////////////////////
//this does not work for the array? WHY NOT!!!!!!!!
this.createEmptyMovieClip("loadTarget_mc", 0);
loadVariables("city.txt", this.loadTarget_mc);
this.loadTarget_mc.onData = function() {
trace("Data Loaded");
trace("activeCity = "+_root.loadTarget_mc.activeCity+" <----- Right Durrr ");
// works for a text box!!!!!!!!!!!!!!!!
shout.htmlText = _root.loadTarget_mc.activeCity
};
//this works?!!???
activeCity = "Wellington"
////////////////////
// NZ City Array: //
////////////////////
var cityArray:Array = new Array();
cityArray.push({city:"Dunedin", horz:"230", vert:"50"});
cityArray.push({city:"Christchurch", horz:"180", vert:"50"});
cityArray.push({city:"Wellington", horz:"550", vert:"550"});
cityArray.push({city:"Auckland", horz:"550", vert:"450"});
cityArray.push({city:"Nelson", horz:"550", vert:"350"});
cityArray.push({city:"New Plymouth", horz:"350", vert:"450"});
cityArray.push({city:"Trarnaki", horz:"450", vert:"550"});
cityArray.push({city:"Rotarua", horz:"450", vert:"350"});
/////////////////
// Read Array: //
/////////////////
var i:Number;
for (i=0; i<cityArray.length; i++) {
// city: Dunedin, Chistchurch, wellington
trace("city = "+cityArray*.city);
trace("hroz = "+cityArray*.horz);
trace("vert = "+cityArray*.vert);
}
///////////////////
// search array: //
///////////////////
//search
_global.search = function() {
erg = cityArray.find(function (comp) {
return comp.city == activeCity;
});
//return
trace("found: "+erg.city);
trace("horz = "+erg.horz+" vert = "+erg.vert);
//cheers!
horz = erg.horz;
vert = erg.vert;
shout.htmlText = "good job "+activeCity;
/////////////////////////
trace("****finished search****");
};
/////////////////////
// button actions: //
/////////////////////
//go!
btn_01.onRelease = function() {
activeCity = "Wellington";
_global.search();
};
btn_02.onRelease = function() {
activeCity = "Auckland";
_global.search();
};
btn_03.onRelease = function() {
/////////////////load the vars:
loadVariables("city.txt", 0);
trace("activeCity = "+activeCity);
};
////////////////////
////////////////////
_global.search();
//I'm a moron
FLA file located here:http://gomi.co.nz/rar/moveit3.fla
Cheers to anybody who can shed some light!
thanks