[mx] pro help needed for prototypes

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:


_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

Ooops!

here’s the fla

Make a function like this:


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:


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

Regards,
Viru.

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:


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

Then when you call it:


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

Regards,
Viru.

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

there are 5 more coming along soon!

thanks,

Kd

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!

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
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.