# What's wrong with this function?

**URL:** https://forum.kirupa.com/t/whats-wrong-with-this-function/14944
**Category:** Uncategorized
**Created:** [March 4, 2003, 6:26pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944 "2003-03-04T18:26:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)
#### Post date: [March 4, 2003, 6:26pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/1 "2003-03-04T18:26:07Z")

</div>

```php

MovieClip.prototype.nc = function(){
	Math.round( Math.random()*0xFFFFFF );
	myColoredObject = new Color (this);
	myColoredObject.setRGB(myColor);
}

```

then i call the function by placing an action on the mc that says:

```php

onClipEvent(enterFrame){
	nc();
}

```

---

<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: [March 4, 2003, 6:32pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/2 "2003-03-04T18:32:55Z")

</div>

pssst… you never defined the variable myColor 😉

---

<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: [March 4, 2003, 6:41pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/3 "2003-03-04T18:41:27Z")

</div>

lmao

genius beta … pure genius

right so now the code looks like this:

```php

MovieClip.prototype.nc = function(){
	myColor = Math.round( Math.random()*0xFFFFFF );
	myColoredObject = new Color (this);
	myColoredObject.setRGB(myColor);
}

```

and it’s going skitzo … i’m guessing it’s b/c i tell the mc to do it on (enterFrame) but wheew … it’s changing color 15 times a second … lol

if i do on (load) then it will only set one color … i’d kinda like a transition … i don’t remember the code but a while back there was a code posted here for a random color that tweened itself from one color to the next.

do you remember what it was?

---

<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: [March 4, 2003, 6:44pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/4 "2003-03-04T18:44:48Z")

</div>

Try this…

```php
MovieClip.prototype.nc = function() {
	red = Math.sin(ra += .02)*127+128;
	green = Math.sin(rb += .05)*127+128;
	blue = Math.sin(rc += .09)*127+128;
	myCol = red << 16 | green << 8 | blue;
	myColored = new Color(this);
	myColored.setRGB(myCol);
};

```

---

<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: [March 4, 2003, 6:55pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/5 "2003-03-04T18:55:40Z")

</div>

wonderful

ty

---

<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: [March 4, 2003, 6:56pm UTC](https://forum.kirupa.com/t/whats-wrong-with-this-function/14944/6 "2003-03-04T18:56:18Z")

</div>

No problem…
