# Functions

**URL:** https://forum.kirupa.com/t/functions/64710
**Category:** Uncategorized
**Created:** [September 19, 2004, 3:01am UTC](https://forum.kirupa.com/t/functions/64710 "2004-09-19T03:01:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Zelwyn](https://avatars.discourse-cdn.com/v4/letter/z/3e96dc/32.png) [@Zelwyn](https://forum.kirupa.com/u/Zelwyn)
#### Post date: [September 19, 2004, 3:01am UTC](https://forum.kirupa.com/t/functions/64710/1 "2004-09-19T03:01:52Z")

</div>

[size=+2][color=#680aac][font=Comic Sans MS][size=2]How do you make a function where you type, for example, bladibladiblah(whatever, whatever2, whatever3);, and the whatevers be a variable in the function? Here’s my code:

function colorFade(endRa, endRb, endGa, endGb, endBa, endBb, endAa, endAb, speed) {  
speed = speed;  
myTransform = new Object();  
rA += (endRa-rA)/speed;  
rB += (endRb-rB)/speed;  
gA += (endGa-gA)/speed;  
gB += (endGb-gB)/speed;  
bA += (endBa-bA)/speed;  
bB += (endBb-bB)/speed;  
aA += (endAa-aA)/speed;  
aB += (endAb-aB)/speed;  
myTransform.ra = rA;  
myTransform.rb = rB;  
myTransform.ga = gA;  
myTransform.gb = gB;  
myTransform.ba = bA;  
myTransform.bb = bB;  
myTransform.aa = aA;  
myTransform.ab = aB;  
colorFunction = new Color(this);  
colorFunction.setTransform(myTransform);  
}

Then, on my MC, there’s this:  
onClipEvent (enterFrame) {  
colorFade(-100, 256, -100, 256, -100, 256, 100, 0, 5);  
}

Shouldn’t that pass on the variables I used to call the function to the actual function as endRa, endRb, endGa, etc., etc.?[/size][/font][/color][/size]

---

<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: [September 19, 2004, 2:24pm UTC](https://forum.kirupa.com/t/functions/64710/2 "2004-09-19T14:24:41Z")

</div>

Yes it should…doesn’t it work ?

I’m used to strict data typing to make sure my variables have the right data type. That usually prevents a lot of problems. And I also always declare my vars inside functions.

---

<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: [September 19, 2004, 3:12pm UTC](https://forum.kirupa.com/t/functions/64710/3 "2004-09-19T15:12:46Z")

</div>

[font=Comic Sans MS][color=#680aac]It only has one problem, and that is, that the variables (endRa, endRb, endGa, endGb, endBa, endBb, endAa, endAb, speed) are not being recognized when the function is called. On my MC I have to code to call the function, including what I want the end variables to be, but it doesn’t work.[/color][/font]

---

<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: [September 19, 2004, 6:50pm UTC](https://forum.kirupa.com/t/functions/64710/4 "2004-09-19T18:50:48Z")

</div>

Is this the whole code ? If it is, you might have forgotten to assign an initial value to vars like rA, rB, etc, which are all undefined.  
And like that the calculation your functions makes returns undefined as a result too:  
rA += (endRa-rA)/speed;  
Only endRA and speed are defined.

Try adding vars like this:  
var rA = 0;  
var rB = 0;  
Assuming that they should start at zero ofcourse 🙂

Hope that helps…

---

<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: [September 19, 2004, 7:02pm UTC](https://forum.kirupa.com/t/functions/64710/5 "2004-09-19T19:02:26Z")

</div>

Ah, I see what you mean. In that case you’re using the mc’s timeline to call the function, but it’s on the root’s. So try either:  
\_root.colorFade()  
or even better  
\_parent.colorFade()

or place the onEnterFrame on your main timeline, so you don’t have to worry about anything at all:

mcMyMovieClip.onEnterFrame = function():Void {  
colorFade(-100, 256, -100, 256, -100, 256, 100, 0, 5);  
};

Hope that works! 🙂  
Seems to work for me…color greys out right away 🙂
