# Actionscripting Question

**URL:** <https://forum.kirupa.com/t/actionscripting-question/21546>\
**Category:** flash\
**Created:** [May 22, 2003, 9:16pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546 "2003-05-22T21:16:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjULTRA](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@mjULTRA](https://forum.kirupa.com/u/mjULTRA)\
**Post date:** [May 22, 2003, 9:16pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/1 "2003-05-22T21:16:50Z")

</div>

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:

URLone=“[http://www.urlone.com](http://www.urlone.com)”;  
URLtwo=“[http://www.urltwo.com](http://www.urltwo.com)”;  
URLthree=“[http://www.urlthree.com](http://www.urlthree.com)”;  
rollover1.text = “Button One Text”;  
rollover2.text = “Button Two Text”;  
rollover3.text = “Button Three Text”;

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 9:31pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/2 "2003-05-22T21:31:54Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 10:01pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/3 "2003-05-22T22:01:44Z")

</div>

thats pretty much what i wanted, although it seems a little complicated. Am i to put the URLs in the ‘var goTo’ line such as this?

var goTo = [“[http://www.aol.com](http://www.aol.com)”, “[http://www.nbc.com](http://www.nbc.com)”, “[http://www.cbs.com](http://www.cbs.com)”, “[http://www.abc.com](http://www.abc.com)”, “[http://www.kirupa.com](http://www.kirupa.com)”];

BTW: My goal was to write an Animated Rollover Buttons Tutorial, but i didn’t want it to be too complicated.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:08pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/4 "2003-05-22T23:08:10Z")

</div>

Well reusing clips isn’t always easy 😉

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:11pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/5 "2003-05-22T23:11:10Z")

</div>

With that last file as an example since you aren’t use a for loop you don’t need to use arrays and can shorten your coding this way…

::check attachment::

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:13pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/6 "2003-05-22T23:13:28Z")

</div>

sweet! this seems to be exactly what i needed.

Once again, LIB saves the day!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:16pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/7 "2003-05-22T23:16:40Z")

</div>

Cool, glad I could help 🙂

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:19pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/8 "2003-05-22T23:19:08Z")

</div>

well, since you mention it…

why doesn’t a new window open when the button is clicked?

is it set up to work like getURL?

can it also be used to load a swf dynamically, like with loadMovie?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:24pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/9 "2003-05-22T23:24:48Z")

</div>

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.

:check attachment:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 11:31pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/10 "2003-05-22T23:31:17Z")

</div>

: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!!

thanks a lot! :cool:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 5:46pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/11 "2003-05-28T17:46:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 6:24pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/12 "2003-05-28T18:24:41Z")

</div>

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…

Remove all of this… [AS]button1.clickMe.onPress = function() {  
getURL(“[http://www.cbperformance.com](http://www.cbperformance.com)”, “\_blank”);  
};  
button2.clickMe.onPress = function() {  
getURL(“URL2”, “\_self”);  
};  
button3.clickMe.onPress = function() {  
getURL(“URL3”, “\_top”);  
};  
button4.clickMe.onPress = function() {  
getURL(“URL4”, “\_blank”);  
};  
button5.clickMe.onPress = function() {  
getURL(“URL5”, “\_self”);  
};[/AS]

And add the on (press) {} commands to the buttons themselves as you did with the rollOver and rollOut.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 6:33pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/13 "2003-05-28T18:33:51Z")

</div>

its cool if you are busy, dont sweat it.

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.

thanks for your help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 7:05pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/14 "2003-05-28T19:05:45Z")

</div>

Well after attempting something real quick I came up with this…

Remove all actions from the button in the clip.

Add a stop action to frame 8.

Update the actions on the frame with this…  
[AS]button1.nameLabel.text = “CB Performance”;  
button2.nameLabel.text = “you want”;  
button3.nameLabel.text = “this”;  
button4.nameLabel.text = “thing”;  
button5.nameLabel.text = “to say”;  
Button.prototype.rollFade = function() {  
this.onRollOver = function() {  
this.\_parent.gotoAndPlay(2);  
};  
this.onRollOut = function() {  
this.\_parent.gotoAndPlay(9);  
};  
};  
//using dynamic event handlers we can remove the on(press) command from the button itself  
button1.clickMe.rollFade();  
button1.clickMe.onPress = function() {  
getURL(“[http://www.cbperformance.com](http://www.cbperformance.com)”, “\_blank”);  
};  
button2.clickMe.rollFade();  
button2.clickMe.onPress = function() {  
getURL(“URL2”, “\_self”);  
};  
button3.clickMe.rollFade();  
button3.clickMe.onPress = function() {  
getURL(“URL3”, “\_top”);  
};  
button4.clickMe.rollFade();  
button4.clickMe.onPress = function() {  
getURL(“URL4”, “\_blank”);  
};  
button5.clickMe.rollFade();  
button5.clickMe.onPress = function() {  
getURL(“URL5”, “\_self”);  
};[/AS]

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 7:41pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/15 "2003-05-28T19:41:51Z")

</div>

Thank you, lost! this finally works!!

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 7:49pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/16 "2003-05-28T19:49:27Z")

</div>

Wow, you were right, it was the tint. I was racking my brain trying to figure out what was up lol.

Well at least everything finally works 🙂

I am attaching the file here just in case your comp goes all ballistic retard on you again.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 8:21pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/17 "2003-05-28T20:21:29Z")

</div>

haha. thanks. i was about to upload it myself to share with people, but i think i’ll just attempt to turn it into a tutorial.

Do you think there would be demand for a “Dynamic Rollover Menu” tutorial?

Also, would you mind if i used your code for the tutorial? You would of course get credit for your contributions…

\<object classid=“clsid:D27CDB6E-AE6D-11cf-96B8-444553540000” codebase=“[http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0](http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0)” width=“200” height=“200”\>  
\<param name=“movie” value=“[http://www.igovw.com/rollover.swf](http://www.igovw.com/rollover.swf)”\>  
\<param name=“quality” value=“high”\>  
\<param name=“menu” value=“false”\>  
\<param name=“wmode” value=“transparent”\>  
\<embed src=“[http://www.igovw.com/rollover.swf](http://www.igovw.com/rollover.swf)” menu=“false” quality=“high” pluginspage=“[http://www.macromedia.com/go/getflashplayer](http://www.macromedia.com/go/getflashplayer)” type=“application/x-shockwave-flash” width=“200” height=“200”\>\</embed\>\</object\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 9:50pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/18 "2003-05-28T21:50:19Z")

</div>

A demand? Hmm, maybe. I know I use dynamic menus a lot, they come in handy big time, so perhaps there could be a demand for it.

And you can use my code all you want. Open source 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 9:59pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/19 "2003-05-28T21:59:17Z")

</div>

just a shorter way to do it (i guess) 🙂

```auto
captionsArray = ["CB Performance", "you want", "this", "thing", "to say"];
urls = ["http://www.cbperformance.com", "URL2", "URL3", "URL4", "URL5"];
Button.prototype.rollFade = function() {
	this.onRollOver = function() {
		this._parent.gotoAndPlay(2);
	};
	this.onRollOut = function() {
		this._parent.gotoAndPlay(9);
	};
};
for (i=1; i<6; i++) {
	this["button"+i].nameLabel.text = captionsArray[i-1];
	this["button"+i].clickMe.rollFade();
	this["button"+i].clickMe.onPress = function() {
		getURL(urls[i-1], "_blank");
	};
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2003, 10:03pm UTC](https://forum.kirupa.com/t/actionscripting-question/21546/20 "2003-05-28T22:03:37Z")

</div>

Thats sorta like what I did the first time ahmed.

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.

[Next page](https://forum.kirupa.com/t/actionscripting-question/21546.md?page=2)
