I posted this question on another forum (in a land far, far away) and received an answer on using arrays. I was wondering if I could use some inequality ( != ) thing that looked at any value except the one chosen. Gads, let me explain better: I load swfs for these buttons and the button (actually an mc) goes to it’s _disabled state when selected. Now when another button is selected, I need the _disabled button to go back to it’s _up state. But since I don’t know how to tell which was selected, I have this poor code below (it works, but it is cumbersome). Here’s the original posting:
I hope this is not a “newbie” question. I am trying to convert my site to all ActionScript and mc’s for buttons. All my button code is in the first frame. I know there must be a way to clean up the code below. What I need (I guess) is my button mc to go to it’s _down state when selected and then go back to it’s _up state when another button is selected. The _down state is fine but I have really ugly, redundant code for the return to the _up state.
Fortunately, I only have a few buttons but I know the code can be neater. This is the code I have for each button (this example is the portfolio button). I am open and eager for any suggestions to eliminate the redundant “whatever_btn.gotoAndStop(”_up");".
I didn’t test this code so I can’t guarantee it will work but it should. What I did was throw all your buttons into an array then write a function that would go through each one and check if it was the button that was clicked. If it was then it would not do anything, if not it sends the button to the _up frame. Doesn’t really cut down on the ammount of code but if you add more buttons it makes it a bit easier to update because you just add another name to the array and increase the number in the for statement.
and really compact this code. I really appreciate your time and talent. You are absolutely right with making it easier to update it in one place, which is the reason I am trying to do it all in ActionScript. Now let’s see if I can apply it!
I think I could even use something I saw where “item” was used to represent both the button and the swf to be loaded. So that when portfolio_btn was selected it grabbed portfolio.swf ( I think it was something along the lines of item.swf and item_btn, I have the code someplace and will repost when I have used what you wrote ).
Thanks so much for the insight and creative manner to approach this.
thanks! I hope to have the chance to work with your code this weekend. If so, I’ll post what I have and the code with the “item” reference I posted above.
Here’s that code with the “item” being used. So I will try to combine what you gave me Sorcerer with this to make some nice, easy-to-update code. It looks like I need to switch the item stuff for your arrays . . . (sound right?) boy, am I clueless . . .
yes, you can do it all with one loop script as well similar to the for script i used in the button selected. put your code inside a loop and then where you have item+"_btn" replace that with button_name*+"_btn"
i believe that should work, if you want you can post the fla and I can take a look at it for you.
so, is this script a loop? if so, i guess that’s why it won’t actually play my button (actually mc) animations. the gotoAndPlay for the _over state is a series of 10 frames but this code only allows frame one to play (i guess it rips through the code each frame right?).
here’s what I have so far that is functional (but as indicated above, i am clueless and the over does not actually play but the code itself works)
so you see i still have your code, which i have a feeling is a better approach but am not sure how to make it work. would your code allow for even more efficient scripting? my big concern is the effect on older slower pc resources and writing the nicest code possible
thanks for all your time and patience, i am starting to “see” these challenges a bit more clearly
edited note: hey, how did that line below appear in the code that I copied back out of flash?
This should work, I’m sure there is more you could do as far as streamlining your code or making it easier to update but I don’t know how exactly you are doing everything, this should work for setting up your button code. About it running better on slower machines, the exact same thing is being done but in a different way. I also took out all the if statments I wasn’t sure why those were in there. You might look up some tutorials on arrays they may help you, if you are interested in generating your menu entirely from the code you might look at this dynamic menu I made to which uses actionscript to make the entire menu. http://www.kirupaforum.com/showthread.php?s=&threadid=8962
Thank you Sorcerer! Your rewrite really did reduce the amount of code! All the if statements are for the Barney-like menu (which I bet could be also done as an array) and the functionality of the email button (prints a page), the client login dialog, et cetera.
I’ll change my code to what you have and post the fla.
I really appreciate all your help, time and knowledge. I am starting to understand how to look at these challenges. Do you teach professionally? If not, Macromedia is missing out on someone with quite a gift. Thank you so much!
I was seeing the light, now I am in the dark again. I took your code Sorcerer and stuck it in the swf. Some functionality is there but I messed something up! Seems only the onRelease is working. And I don’t understand where to place the return to enabled state:
function Enable_Button(selected){
for (i=0;i<=8;i++){
if(Button_Name* !== selected){
_root[Button_Name*].gotoAndStop("_up");
}
}
}
I much prefer your code using arrays then what I initially had. But I obviously have implemented it incorrectly and have not found the error of my ways . . .
The flas are too big for here but I placed your coded array version here at:
The fla is 684 KB and if you have the time and inclination, I would greatly appreciate your continued help (or big smack on the side of my head!). Thank you.
Hi Sorcerer, I have really learned a lot from your code and it is really well written. I have worked it a bit with the help of the actionscript.org forum and here is what your initial code has evolved to (minus all the "if"s which are in the final fla):
To put in the code i use the code vB code, use it the same as the php but put the word code in place of php.
I added what you should need for your enable function, declare the enable function on the frame with all your other code and just call the function from your onRelease function.