|
-
[F8] Quicker way to write these button actions
Hi there,
I have 30 buttons, that i need to code all the same, except for changing the number.
I'm sure you can do this by using arrays or something.
so my array would look like:
PHP Code:
var buttons = "1","2","3"...."29","30";
And the buttons i'm trying to create would look like:
PHP Code:
button1.onRelease = function (){
button1.gotoAndStop("selected");
}
button2.onRelease = function (){
button2.gotoAndStop("selected");
}
button3.onRelease = function (){
button3.gotoAndStop("selected");
}
But i want to achieve this in 2 lines, something like this
PHP Code:
['button' + [buttonVariable]].onRelease = function(){
['button' + [buttonVariable]].gotoAndStop("selected");
}
Can anyone help?
-
Senior Member
How can you associate a gotoAndStop action to button... I suppose these would be movie clips... Can you please verfiy and clarify to us...
As ever,
Vinayak
-
http://www.in3d.eu
Hi all,
Except of the issue noted by vinayak.kadam, a general code to achieve this would be for example:
PHP Code:
for (i=1;i<=30;i++){
//Assume all buttons are in the _root (main stage) otherwise you have to provide
// the correct target path eg. _root.Container["button"+i] (if they are inside a "Container" clip for example)
var myButton=_root["button"+i]
myButton.onRelease=function(){
trace(this)
this.gotoAndStop("selected");
// Your rest actions here..
}
}
Best!
Kostas
Last edited by Kostas Zotos; 05-14-2008 at 01:58 PM.
-
yes, that's exactly it.
Sorry, yeah i'm using movie clips, not buttons. (my bad).
-
Senior Member
Thats ok! It happens.... anyways Kostas has mentioned the correct method above to achieve this....
As ever,
Vinayak Kadam
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
|