PDA

View Full Version : for loop button deinifiton???


raskolnikov
08-21-2006, 06:33 AM
flashers,

basically, i have 20 buttons. i wanna set each button upon click to spit out a variable. i=1 for btn1, i=2 for btn2. etc...

here's a section of my code. though it doesn't work and when each button is click i=20 comes out coz the loop terminates at 20. so now i gotta script each indiviual button onRelese action out of the loop. how can i set the script in a for loop with multiple buttons all containing their individual variable?

for (i=1; i<20; i++) {
this["xlimit"+i] = (i-1)*gap;
//trace("sssssssssssssssss"+eval("xlimit"+i));
eval("timeline.but"+1).onRelease = function() {

this["timeline"].onEnterFrame = function() {
if (timeline._x<=eval("xlimit"+i)) {
delete timeline.onEnterFrame;
} else {
timeline._x -= speedBut;
}
};
};
}

mooska
08-21-2006, 06:41 AM
for (i=1; i<20; i++) {
//this["xlimit"+i] = (i-1)*gap;
var k:Number;
var mc:MovieClip = this.timeline["but"+i];
mc.k = (i-1)*gap;
mc.onRelease = function() {
k = this.i;
this._parent.onEnterFrame = function() {
if (this._x<=k) {
delete this.onEnterFrame;
} else {
this._x -= speedBut;
}
};
};
}
Not sure of it, didnt exactly get what you want :)

raskolnikov
08-21-2006, 07:32 AM
ok your script also does the same as mine.

each button spit out i=20;

i want each button to spit on their own unique variable.

i sent you 2 files. one is correct but code is lengthy and i had to define each button onRelease function.

all i want is a for loop for the buttons spitting out their own unique number. in teh second file i put your code in it. click on the button you will see the trace variable is the same . 20. the end of the for loop. how to solve this?

mooska
08-21-2006, 08:45 AM
One little mistakefor (i=1; i<20; i++) {
this["xlimit"+i] = (i-1)*gap;
var k:Number;
var mc:MovieClip = this.timeline["but"+i];
trace(mc);
mc.k = (i-1)*gap;
mc.onRelease = function() {
k = this.k;
trace("You number is: "+this.k);
this._parent.onEnterFrame = function() {
trace(k);
if (this._x<=k) {
delete this.onEnterFrame;
} else {
this._x -= speedBut;
}
};
};
}
It was k, not i :)

raskolnikov
08-21-2006, 09:24 AM
yeah. it certainly was. it works thanks. what is the trick? use 2 variables instead of one? i am not sure what i did wrong. perhaps u can enlighten me so i won't repeat the same mistake again.

thank you :cool:

mooska
08-21-2006, 09:30 AM
Normally, you just assign variable to the button, and then if you want it, just put this.youvar and you get your uniqe var
But what i did this time was something more, cause onEnterFrame was on something alse, not on a button, so i ve created local variable, and when a button is pressed, this var gets this buttons uniqe var.
and then i can use this variable, not knowing from what button it came from.