actionscript question
- Started
- Last post
- 11 Responses
- flyingnowhere
actionscript 2.0
so ive got a map of the US
each state is a button name after the state
any way to turn the mc name into a variable?stateName = this.mcName.toString;
something like that
- jsaul0
why ?
- flyingnowhere0
so i can plug something like this into each buttons action and be done with it
stateName = this.mcName.toString;
on(rollOver){
stateName.text = stateName;
}
on(rollOut){
stateName.text = "";
}
on(release){
getURL("/results/ppc/?q=" + stateName);
}
- whiteout0
stateName = this.mcName._name;
- flyingnowhere0
im trying to avoid typing every state name in the actions of each state
- ornj0
maybe put references to the states into an array?
var states:Array = [...];
for(var i:Number = 0; i < states.length; states++) {
states[i].onRelease = function() { ... }
states[i].onRollOver = function() { ... }
// I do this to avoid the button getting stuck.
states[i].onRollOut =
states[i].onDragOut =
states[i].onReleaseOutside = function() { ... }
}- thats a little much for meflyingnowhere
- If you want to avoid copy pasting code 50 times its what you have to do. Suck it up.ornj
- hahahmikotondria3
- thatblokemike0
if you had class names for the counties then it would trace them when calling toString so just export each one as a class. I imagine at the moment its saying [ movieclip ]... I guess you'll still get the square brackets even when they are classes, get rid of them with a string operation. something like
var countyname:String = this.toString().split(" ")[1].toString().split("]")[0];
- flyingnowhere0
what do i need to do to get this to a string
buttonName = this._name;- a string may not even be what i need, im in a little too deepflyingnowhere
- flyingnowhere0
so is it just not possible to turn the name of a button into a variable
i cant find anything online about it
- mikotondria30
well what do you get when you:
trace(this);
and
trace(this._name);
from within your buttons...?
- anxiousarms0
var string:String = mcInstanceName;
trace(string);done.
tho, if you named the states more generic and ran them through a loop like ornj suggests then it will make your life A LOT easier.
- but dont i have to type each state name on every button like that
var string:String = washington;flyingnowhere - yes, exactly why we keep telling you to use a loop.anxiousarms
- but dont i have to type each state name on every button like that