I have created an animated rollover effect that consists of a button that is motion tweened inside of a movie clip with the instance name, “rollover”. Also inside this movie clip is a dynamic text box with the variable ‘text’.
I would like to use this one movie clip multiple times, but i would like to code it so that when the button is clicked, it uses information from AS that is in the root directory. For example: the button would have something like:
on (press) {
if instance name is rollover1, then getURL(“URLone”, _blank");
if instance name is rollover2, then getURL(“URLtwo”, _blank");
else getURL(“URLthree”,_blank");
}
and the AS in the main would contain something like this:
Each button would have an instance name of rollover1, rollover2, and so on…
The idea is to be able to use the same button rollover clip for all the buttons, but have a different name show on the button, and have a different URL to go to. I know it can be done, im just not sure how.
Since I can’t think of how to explain it in English right now check my attached file with commented coding.
[edit]
Please note that there are multiple ways of getting this to work. You can use movie clips as buttons to make it easier, but since your animating it still needs to be in a clip.
And you don’t need to place the actions on the button itself. You can give the button an instance name and target it in the for loop via an onPress dynamic event handler.
[/edit]
Animated rollOvers reusing the same clips as buttons isn’t exactly as easy as just making buttons. You don’t need to use a for loop to create the clips if you don’t want, you can instead drag multiple instances of the clip onto the stage at once, give them all an instance name and target them that way.
And yes, you populated that array correctly.
I modified the original file as attached. I removed the for loop and dragged instances of the clip onto the stage manually and gave them instance names.
I also wrote the arrays in a different manner. There are many ways to write arrays (4 if I remember correctly) so this is just another method if you think it is easier.
Its more coding, but if you think it is easier and it still works, then what the heck right?
I have a habit of overdoing my coding sometimes, so don’t mind me…lol. I think that last file is more along the lines of what you actually needed. I can optimize that even more with prototypes probably…hmmm. Im bored, looking for something to do, have an idea… I think I will try it.
Since I love dynamic event handlers I used that method instead. It keeps all the coding neccesary in one area and makes it easier to edit and allows you to do whatever you want for each button.
:shouts outloud, like an herbal essence commercial:: “yes yes yes!!”
this is awesome… i wanted to have multiple buttons, with the same rollover effect, but without having to create six different buttons with six different commands. This allows me to recycle the same button clip, change a few instance names, and add all the details in the actionscripting! I love it!
If i do manage to write a tutorial, you can be sure that you will get the props that you deserve!!
LIB: On friday, i had a working version on my desktop, and now it is gone. Now i can’t get the code to work with the rollover effects, and its frustrating the hell out of me.
Your FLA’s work fine, but they stop working after i make the button rollover animated. Attached is the FLA that i am working with, and im wondering if you can take a look at it (when you get a chance) to tell me where i am going wrong. Thanks.
My guess is that when i add the on(rollOver) commands to control the button rollover animation, it somehow conflicts with the onPress AS. I’ve experimented, but with no luck.
Well I don’t know the exact problem, it may because of the tween, or because of the onPress command, I don’t have much time to figure this out right now so heres a quick workaround…
That workaround defeats the purpose, which is having the commands in the AS. The Flash files you supplied work well, but they cease to work once i create the rollovers. The thing that sucks is that i had a working version on Friday, and when i came back on Tuesday, it was no longer there. My computer is set up so that a lot of my files are stored on a server, including my desktop, and the My Documents folder, and screwy stuff is always happening. The same three folders that i delete everyday, will magically reappear every morning. Its kinda frustrating, but i’ve learned to live with it.
The thing is this though, when you press down you have the hit state of the button turn white. This only works between frames 2-7 and 9-14. The only frame it doesn’t work on is frame 8. I really don’t know why though, but frame 8 is the frame we stop on with the rollOver, so I don’t get it. I am guess it might be the tween that is causing this problem, but I don’t know for sure.
I’m pretty sure that the hit state doesn’t show in frame eight because I have tint set at 100%. As a matter of fact, i changed it to 50%, and now you can see the button turn white when it is pressed. Again, thanks a lot for helping me with this.
But the thing is, people might not want to name their buttons in succession like that and instead have individual names.
And that would involve the creation of another array and blah blah blah…lol.
And also seperate onPresses allow for not only getURLs but for loadMovies or getURLs or attachMovies or whatever they want for each button, and it isn’t limited to just one thing.