# \[mx\] pro help needed for prototypes

**URL:** https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966
**Category:** flash
**Created:** [August 20, 2003, 4:19pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966 "2003-08-20T16:19:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kdzines](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kdzines](https://forum.kirupa.com/u/kdzines)
#### Post date: [August 20, 2003, 4:19pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/1 "2003-08-20T16:19:00Z")

</div>

hey everyone,

Been a while hope everyones good.

I need some help on how to make my animations more efficient and functional by putting repeating code into a function or prototype.

Here’s an example of the sort of animations i mean:

```php

_root.content.box._xscale = 0;
_root.content.box._yscale = 0;
_root.content.mask._xscale = 0;
_root.content.mask._yscale = 0;
_root.content.maintext._alpha = 0;
_root.content.pic._xscale = 0;
_root.content.pic._yscale = 0;
duration1 = 20;
duration2 = 10;
duration3 = 15;
duration4 = 20;
duration5 = 15;

b=0;
t=0;
r=0;
h=0;
y=0;

this.onEnterFrame = function(){
	if(Go == true){
	if(t<duration1){
		_root.content.box._xscale = Math.EaseOutBack (t,0,100,duration1);
		t++;
		}
		if(t>=(duration1/3)){
			if(b<duration2){
			_root.content.box._yscale = Math.EaseOutBack (b,0,100,duration2);
			b++;
				}
			}
			if(b>=duration2){
				if(r<duration3){
					_root.content.mask._xscale = Math.EaseOutQuint (r, 0, 100, duration3);
					_root.content.mask._yscale = Math.EaseOutQuint (r, 0, 100, duration3);
					r++;
					}
				}
				if(r>=duration3){
					if(h<duration4){
						_root.content.maintext._alpha = Math.EaseInExpo (h, 0, 100, duration4);
						h++;
						}
					}
					if(h>=(duration4/2)){
						if(y<duration5){
							_root.content.pic._xscale = Math.EaseOutCirc (y,0,100,duration5);
							_root.content.pic._yscale = Math.EaseInOutElastic (y,0,100,duration5);
							y++;
							}
						}
	}
	}
	
button.onPress = function(){
	Go = true;
	}

// BTW - i have used penner's eqs

```

I have attached the fla so you can see what it looks like.

Now this method works fine and i get the desired animation etc. However it’s bloody inefficient!

Let’s say i got a site to do where this animation is exactly the same, but there are 20 sections each with there own heading, text and pic. How do i go about putting this code in once and then referencing it whenever necessary?

If someone could make this a prototype, or explain how to go about doing this, i would be very grateful.

in this particular case, i ideally want the site to be all on 1 frame, with different sections preloading when the various buttons are pressed and then the animation commencing once the content for each section is loaded. I don’t really need help for the preloading or anything, just a good way to reference the animation without having to write this code over and over.

Thanks guys,

Kd

---

<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: [August 20, 2003, 4:20pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/2 "2003-08-20T16:20:08Z")

</div>

Ooops!

here’s the fla

---

<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: [August 20, 2003, 6:24pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/3 "2003-08-20T18:24:11Z")

</div>

Make a function like this:

```auto

function functionName() {
//then put all that code in here.
} //End of function.

```

Now you can call the function by calling its name. In a button for example:

```auto

on(release) {
functionName(); // This will call the function and execute it.
}

```

Regards,  
Viru.

---

<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: [August 20, 2003, 6:27pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/4 "2003-08-20T18:27:26Z")

</div>

Forgot to mention about passing an argument in the function. Inm your case i guess you would want to pass the Go vairable as an argument.

Siimply done like this:

```auto

function myFunction(Go) {
//code here.
}

```

Then when you call it:

```auto

on(release) {
Go = true;
myFunction(Go);
}

```

Regards,  
Viru.

---

<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: [August 21, 2003, 4:22pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/5 "2003-08-21T16:22:32Z")

</div>

hey thanks for the help.

I’m a bit confused about passing an “argument”, can you explain it a bit more please?

The other main problem i have is that i want the animation to repeat everytime i press a different button.

Any clues on how? I always have problems with penner because i am not clear on the best way to reset my variables.

oh + talking of sytel without substance, check out my newest launched website,

[www.domakaya.com](http://www.domakaya.com)

there are 5 more coming along soon!

thanks,

Kd

---

<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: [August 21, 2003, 4:30pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/6 "2003-08-21T16:30:27Z")

</div>

Let’s say you want to apply the same effect to five different movies (btw, I havent tried your effect, but the principle applies)…

So, you have five movies, name one\_mc, two\_mc, three\_mc and so on…

You want a function to do the same thing to the five movies, so you create a function like this

animator=function(moviename){  
moviename.onEnterFrame=function(){  
trace("works for button: " + moviename);  
}  
}

now, if you have a corresponding button for each movie, you would add the movieclip name to the animator function, therefore passing the argunemt…

button1.onRelease=function(){  
animator(one\_mc);  
}  
button2.onRelease=function(){  
animator(two\_mc);  
}

and so on…

good 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: [August 22, 2003, 9:01pm UTC](https://forum.kirupa.com/t/mx-pro-help-needed-for-prototypes/28966/7 "2003-08-22T21:01:26Z")

</div>

thanks for the help guys.

I’m stil a bit confused, but i’ll spend some time on it. Know of any good tutorials online that really explain the principles of functionsand protoypes?

i’ve been reading the one on kirupa  
[http://www.kirupa.com/developer/actionscript/tricks/prototypes.htm](http://www.kirupa.com/developer/actionscript/tricks/prototypes.htm)  
but seeing as i don’t really get functions, it’s a bit vague for me.

anyways cheers guys, i’ll let you know how i got on.
