-
Hi,
How do I loop through 10 button names?
Button1.onPress = function() {
addToArray();
};
Button2.onPress = function() {
addToArray();
};
.
.
.
.
Button10.onPress = function() {
addToArray();
};
I had something like this in my mind:
Button[i].onPress = function() {
addToArray();
};
-but nope it doesn't work.
Thanks,
Kyungnielsen
-
Ups,
Button(i).onPress = function() {
addToArray();
};
The i in brackets [] became italic.
I hope you got my point
Thanks,
Kyungnielsen
-
you forgot the for
Code:
for(i=1;i=10;i++){
Button(i).onPress = function() {
addToArray();
};
}
or you could
Code:
for(i=1;i=10;i++){
_root["Button"+i).onPress = function() {
addToArray();
};
}
-
Great - Thanks
cheers,
Kyungnielsen
-
Hi,
Now I have an add on for this problem:
I generates x buttons based on input from a array with the following code:
<br>
<hr><br><pre>
for (m=0; m<WrongOnes.length; m++) {
_root.fb.attachMovie("BackToQuestions", "QNumberWrong"+[m], WrongOnes[m]);
//Simple alignment of number on button
if (WrongOnes[m]<10) {
p = " "+(WrongOnes[m]+1);
} else {
p = (WrongOnes[m]+1);
}
_root.fb["QNumberWrong"+m].QuestionNumber = p;
//Placement
_root.fb["QNumberWrong"+m]._x = -90+m*distance;
_root.fb["QNumberWrong"+m]._y = 25;
_root.fb["QNumberWrong"+m].dynamicButton.onRelease = function() {
i = m;
FeedbackDisplay();
};
}
<hr><br>
</pre>
When one of dynamic buttons is pressed it's going to update the display by splitting some arrays(i) into different text fields.
The looping dosen't work as it assign the last value of m to all the i on all the buttons. <br>The functionallity I am looking for is: When button 1 is pressed split array(1), when 2 is pressed split array(2), button(i) --> array(i) and so on
Any suggestions on how to solve this?
cheers,
KyungNielsen
-
Code:
_root.fb["QNumberWrong"+m].dynamicButton.prototype.onRelease = function() {
i = m;
FeedbackDisplay();
};
well your still not using the prototype method to assign events and methods to your objects
-
Well this prototype thing seems to scare me off
Even with your help (I really appreciate it - thanks) I can't make it work.
It works fine if I hardcode it, so the path & syntax should be ok, but then there obvious is no reason for creating dynamic buttons.
I'll keep on figthing....
-
when ever you type in
object.method = function()
insted type
object.prototype.method = function()
and thats about it if your assigning a function use the prototype method
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|