Ok, I am going nuts....
I have this flash file that's a map of counties in Alabama, I've made each county a Button symbol and gave each instance a name like [countyname]_btn, for example baldwin_btn. I am trying to set the onRelease event to call a function that takes the name of a county and calls an external JavaScript function. Instead of adding code for each button (there's 67 countys in Alabama, 67 * 3 lines of code = 201 lines of code ) I am attempting to write a small piece of code that automatically cycles through all the button instances and sets the correct onRelease call.
Here's what I have so far:
I thought this would work OK but in reality, it doesn't Clicking on any county results in one county name being printed. I've set a breakpoint and ran through the debugger and everything looks OK, it's setting the correct values and all but each anonymous function isn't retaining the correct value.... Any ideas?
EDIT: For some reason there's a gaping space problem on the loadCompanies function line, this isn't present in my actual code in Flash just when posting the code to the board. I tried deleting + retyping that line but it's not fixing the space
Thanks,
Zalbag
I have this flash file that's a map of counties in Alabama, I've made each county a Button symbol and gave each instance a name like [countyname]_btn, for example baldwin_btn. I am trying to set the onRelease event to call a function that takes the name of a county and calls an external JavaScript function. Instead of adding code for each button (there's 67 countys in Alabama, 67 * 3 lines of code = 201 lines of code ) I am attempting to write a small piece of code that automatically cycles through all the button instances and sets the correct onRelease call.
Here's what I have so far:
Code:
import flash.external.ExternalInterface;
function loadCompanies(county:String):Void {
// ExternalInterface.call("loadcompanies", "al", county);
trace(county); // testing
}
for (i in this) {
if (this[i] instanceof Button) {
var temp:String = this[i]._name;
var countyName:String = temp.slice(0, temp.indexOf('_'));
this[i].onRelease = function():Void {
loadCompanies(county);
}
}
}
I thought this would work OK but in reality, it doesn't Clicking on any county results in one county name being printed. I've set a breakpoint and ran through the debugger and everything looks OK, it's setting the correct values and all but each anonymous function isn't retaining the correct value.... Any ideas?
EDIT: For some reason there's a gaping space problem on the loadCompanies function line, this isn't present in my actual code in Flash just when posting the code to the board. I tried deleting + retyping that line but it's not fixing the space
Thanks,
Zalbag