# Asigning functions to an array

**URL:** <https://forum.kirupa.com/t/asigning-functions-to-an-array/58161>\
**Category:** Uncategorized\
**Created:** [July 20, 2004, 8:34am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161 "2004-07-20T08:34:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fugzi](https://avatars.discourse-cdn.com/v4/letter/f/c67d28/32.png) [@fugzi](https://forum.kirupa.com/u/fugzi)\
**Post date:** [July 20, 2004, 8:34am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/1 "2004-07-20T08:34:14Z")

</div>

hi  
could some one please explane how i would make this code work.  
I have a array of MC that are placed on the stage to make up a logo  
what i would like is to fade through the clips. I thought i could creat an array and atach a fade function to it but it dosn’t seem to work.

here is my code

function init(){  
//create an array for my movie clips  
euro = new Array ( b1,b2,b3,b4,b5,b6,b7,b8,e1,e2,e3,e4,e5,e6,e7,e8  
,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,e20  
,e21,e22,e23,e24,e25,e26,e27,e28,e29,e30,e31,e32  
,e33,e34,e35);  
// create a loop through the array  
for(var i =0 ; i\<= euro.length ; i++){  
euro\*.\_alpha.fade(euro\*);

}  
}  
// activate init()  
init();  
trace(b1.\_alpha);  
// a function to fade the clips  
function fade (theClip){  
theClip.\_alpha = 0;  
theclip.onEnterFrame = function(){  
if(this.\_alpha \<= 50){  
this.\_alpha ++;  
}  
}

please help thank you

---

<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:** [July 20, 2004, 8:48am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/2 "2004-07-20T08:48:51Z")

</div>

this -  
function fade (theClip){

should be this -  
function = fade(theClip) {

and this -  
theclip.onEnterFrame = function(){

should be this -  
theClip.onEnterFrame = function(){

I think…

I’m at work, so I can’t 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:** [July 20, 2004, 9:35am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/3 "2004-07-20T09:35:06Z")

</div>

hi thanks for your help but this wont work i cheked in moocks book and when asigning a function the syntax is function function\_name not function = Name the on enterframe bit i not sure what your getting as far as i can tell there is no syntax problem

cheers for your help though

---

<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:** [July 20, 2004, 9:59am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/4 "2004-07-20T09:59:33Z")

</div>

You had several errors there. Here’s the correct code.

```auto

function init() {
	euro = new Array(b1, b2, b3, b4, b5, b6, b7, b8, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32, e33, e34, e35);
	for (var i = 0; i<euro.length; i++) {
		fade(euro*);
	}
}
function fade(theClip) {
	theClip._alpha = 0;
	theClip.onEnterFrame = function() {
		if (this._alpha<=50) {
			this._alpha++;
		} else {
			delete this.onEnterFrame
		}
	};
}
init();

```

---

<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:** [July 20, 2004, 10:28am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/5 "2004-07-20T10:28:09Z")

</div>

thank you i 'v just tried it works just two more question is there any way i can speed it up i tried increasing the frame rate but it doesn’t work and secondly is there a way of looping through the array so it does the movie clips indavidually.eg one fades up then the next and so on

cheers

---

<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:** [July 20, 2004, 10:36am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/6 "2004-07-20T10:36:09Z")

</div>

Like this:

```auto

fadespeed = 9;
function init() {
	euro = new Array(b1, b2, b3, b4, b5, b6, b7, b8, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32, e33, e34, e35);
	for (var i = 0; i<euro.length; i++) {
		euro*.id = i;
	}
	euro[0].fade();
}
MovieClip.prototype.fade = function() {
	this.go = true;
	this.onEnterFrame = function() {
		this._alpha += fadespeed;
		if (this.go) {
			if (this._alpha>50) {
				this.go = false;
				euro[this.id+1].fade();
			}
		}
		if (this._alpha>=100) {
			delete this.onEnterFrame;
		}
	};
};
init();

```

---

<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:** [July 20, 2004, 10:40am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/7 "2004-07-20T10:40:44Z")

</div>

> [@fugzi](#):
>
> hi thanks for your help but this wont work i cheked in moocks book and when asigning a function the syntax is function function\_name not function = Name the on enterframe bit i not sure what your getting as far as i can tell there is no syntax problem
> 
> cheers for your help though

I wasn’t too sure about the function one, but there was a type in the onenterframe bit. you used ‘theclip’ where you should have used ‘theClip’

sorry, I should have been clearer.

still, looks like you’re all sorted now.

---

<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:** [July 20, 2004, 11:15am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/8 "2004-07-20T11:15:44Z")

</div>

> [@Voetsjoeba](#):
>
> Like this:
> 
> ```auto
> 
> fadespeed = 9;
> function init() {
> euro = new Array(b1, b2, b3, b4, b5, b6, b7, b8, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32, e33, e34, e35);
> for (var i = 0; i<euro.length; i++) {
> euro*.id = i;
> }
> euro[0].fade();
> }
> MovieClip.prototype.fade = function() {
> this.go = true;
> this.onEnterFrame = function() {
> this._alpha += fadespeed;
> if (this.go) {
> if (this._alpha>50) {
> this.go = false;
> euro[this.id+1].fade();
> }
> }
> if (this._alpha>=100) {
> delete this.onEnterFrame;
> }
> };
> };
> init();
> 
> ```

Hi I just tried this carn’t get it to work though it was just a cas of cutting and pasting it wasn’t 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:** [July 20, 2004, 11:24am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/9 "2004-07-20T11:24:13Z")

</div>

Worked here, can you send me your 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:** [July 20, 2004, 11:40am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/10 "2004-07-20T11:40:49Z")

</div>

> [@Voetsjoeba](#):
>
> Worked here, can you send me your fla ?

See attached zip file for fla thank you

---

<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:** [July 20, 2004, 11:45am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/11 "2004-07-20T11:45:11Z")

</div>

Your movieclips are already at alpha 100, it can’t increase anymore. Your movieclips should start at alpha 0. The last if statement says \>=50, that should be \>=100.

---

<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:** [July 20, 2004, 11:52am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/12 "2004-07-20T11:52:44Z")

</div>

thank you very much i just tried it and it works great, just have to examine it to understand it know

cheers  
Fugzi

---

<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:** [July 20, 2004, 11:53am UTC](https://forum.kirupa.com/t/asigning-functions-to-an-array/58161/13 "2004-07-20T11:53:11Z")

</div>

Anytime 🙂
