# \[AS2\] setting variable on rollover

**URL:** https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687
**Category:** flash
**Created:** [April 23, 2006, 6:09pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687 "2006-04-23T18:09:10Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 23, 2006, 6:09pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/1 "2006-04-23T18:09:10Z")

</div>

Hello, hope someone can help…

I am using laco tweening prototypes [http://laco.wz.cz/tween/](http://laco.wz.cz/tween/) and have a little problem which im sure is easy to solve, but i just dont know how…

I have e.g 3 movieclips which i want to animate with a rollover from 3 different buttons - btn1 animates mc1, btn2 animates mc2 etc.

Each mc has the same animation (3 tweens - x,y and rotation) so i have set up a function for the three tweens using a variable for the mc name:

```auto
var my_mc = "mc1";

function PageTween() {
	my_mc.tween("_x", 165, 1, "easeOutExpo");
	my_mc.tween("_y", 75, 1, "easeOutExpo");
	my_mc.tween("_rotation", 1, 1, "easeOutExpo");
}

```

this is so when i rollover btn2 i can change the var my\_mc to “mc2” so that i can reuse the function.

```auto
btn2.onRollOver = function() {
      my_mc = "mc2";
	PageTween()
};

```

but, it doesnt work. I am assuming that the tween ignores the variable.  
is there some way inserting a calculation to get the variable instead of my\_mc at the start of the tween?

thanks for your time

Lee

---

<div class="post-metadata">

### Author: ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)
#### Post date: [April 23, 2006, 6:26pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/2 "2006-04-23T18:26:27Z")

</div>

[AS]function PageTween(my\_mc:MovieClip):Void {  
my\_mc.tween("\_x", 165, 1, “easeOutExpo”);  
my\_mc.tween("\_y", 75, 1, “easeOutExpo”);  
my\_mc.tween("\_rotation", 1, 1, “easeOutExpo”);  
}  
for (i=1; i\<4; i++) {  
this[“btn”+i].ind = i;  
this[“btn”+i].onRollOver = function() {  
PageTween(\_root[“mc”+this.ind]);  
};  
}[/AS] 🙂

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 23, 2006, 7:12pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/3 "2006-04-23T19:12:35Z")

</div>

Hi BlueNar,

Thanks for the quick response, i ahve tried the script provided, and in my main movie that im working on it had no effect, so i tried it on a fresh movie and found that when i included in the laco as:

#include “lmc\_tween.as”

i was gettting an error:

found Number where String is required.  
for (i=1; i\<4; i++) {

I have uploaded the test here \>

[http://www.leeharding.net/test/tweenFunction.zip](http://www.leeharding.net/test/tweenFunction.zip)

i hope you can figure this one out as it is giving me a headache. Thanks for your time, i appreciate it.

regards

Lee

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 24, 2006, 4:22pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/4 "2006-04-24T16:22:09Z")

</div>

does anyone else have any ideas as how i can do this?

thanks

Lee

---

<div class="post-metadata">

### Author: ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)
#### Post date: [April 24, 2006, 4:25pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/5 "2006-04-24T16:25:20Z")

</div>

What is the line of code before the for loop…

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 24, 2006, 4:55pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/6 "2006-04-24T16:55:39Z")

</div>

the code before the for loop

```auto
function PageTween(my_mc:MovieClip):Void {
    my_mc.tween("_x", 165, 1, "easeOutExpo");
    my_mc.tween("_y", 75, 1, "easeOutExpo");
    my_mc.tween("_rotation", 1, 1, "easeOutExpo");
}

```

thanks

Lee

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 24, 2006, 10:25pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/7 "2006-04-24T22:25:11Z")

</div>

> [@MichaelxxOA](#):
>
> What is the line of code before the for loop…

the code before the for loop

```auto
function PageTween(my_mc:MovieClip):Void {
    my_mc.tween("_x", 165, 1, "easeOutExpo");
    my_mc.tween("_y", 75, 1, "easeOutExpo");
    my_mc.tween("_rotation", 1, 1, "easeOutExpo");
}

```

thanks

Lee

---

<div class="post-metadata">

### Author: ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)
#### Post date: [April 24, 2006, 11:19pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/8 "2006-04-24T23:19:00Z")

</div>

can you post the lmc\_tween.as file… laco.wz site is acting strange.

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 24, 2006, 11:49pm UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/9 "2006-04-24T23:49:02Z")

</div>

> [@BlueNar](#):
>
> can you post the lmc\_tween.as file… laco.wz site is acting strange.

tis a strange site…

i used the mxp installer, but here is the as file

let me know if you need the mxp

cheers

Lee

---

<div class="post-metadata">

### Author: ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)
#### Post date: [April 25, 2006, 12:30am UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/10 "2006-04-25T00:30:02Z")

</div>

the problem lies within the laco tween class syntax, which Im unfamiliar with. I replaced it with the tween class to show that the function does work properly.

---

<div class="post-metadata">

### Author: ![leeharding](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@leeharding](https://forum.kirupa.com/u/leeharding)
#### Post date: [April 25, 2006, 12:46am UTC](https://forum.kirupa.com/t/as2-setting-variable-on-rollover/186687/11 "2006-04-25T00:46:13Z")

</div>

> [@BlueNar](#):
>
> the problem lies within the laco tween class syntax, which Im unfamiliar with. I replaced it with the tween class to show that the function does work properly.

thanks - thats going to be helpful for something else im working on…

unfortunately im using the laco tween throughout the site that i need this for…

i will have to try something else… if you get any ideas, let me know.

is there any way i can just use the

```auto
function PageTween(my_mc:MovieClip):Void {

```

without the for loop?

thanks for your time

Lee
