# Why don't you fade?

**URL:** https://forum.kirupa.com/t/why-dont-you-fade/58565
**Category:** Uncategorized
**Created:** [July 23, 2004, 4:30pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565 "2004-07-23T16:30:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)
#### Post date: [July 23, 2004, 4:30pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/1 "2004-07-23T16:30:43Z")

</div>

Hi,

today i’ve written my first function :thumb: the only problem… it doesn’t work properly. Here’s my function:

```auto
function fade() {
i = 1;
while(i<10){
roll._alpha = roll._alpha - 10;
i++
if(i>=10){
gotoAndStop(1);
trace("boe");
}
}
} 

```

the function is located at the second frame inside a mc called “FLASH” , even as the mc “roll”. The mc “FLASH” has the next piece of code:

```auto
on(rollOver){
gotoAndPlay(2);
}on(rollOut){
this.fade();
}

```

So when you rollover it, you will go to frame 2 in mc “FLASH”, where my function and the mc “roll” are. But when I roll out, mc “roll” won’t fade out…☹

What’s my problem?

---

<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 23, 2004, 4:32pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/2 "2004-07-23T16:32:03Z")

</div>

you have to call the function. right after that code put \_root.fade();

then it will work.

🙂

---

<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 23, 2004, 5:18pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/3 "2004-07-23T17:18:09Z")

</div>

how do I have to do that… i’m not very formiliar with this function code… :S

---

<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 23, 2004, 5:19pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/4 "2004-07-23T17:19:34Z")

</div>

b/c a function is just a definition of code, it doesn’t actually execute. you have to call it… all functions really are is a handy way to access a lotta code w/ one line (the call)

so you have to do \_root.fade();

🙂

---

<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 23, 2004, 5:21pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/5 "2004-07-23T17:21:00Z")

</div>

But that is what i do, when i rollout.

```auto

on(rollOut){
this.fade();
}

```

---

<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 23, 2004, 5:24pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/6 "2004-07-23T17:24:10Z")

</div>

And it also traces “boe”, as i have difined in my function… so i has to be a function-problem, right?

---

<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 23, 2004, 5:28pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/7 "2004-07-23T17:28:41Z")

</div>

is it just fading to 0? you _did_ use a while loop… 🙂

---

<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 23, 2004, 5:33pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/8 "2004-07-23T17:33:10Z")

</div>

it’s fading to a negative number, because roll,\_alpha is random.

---

<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 23, 2004, 6:04pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/9 "2004-07-23T18:04:23Z")

</div>

> [@2nd day](#):
>
> it’s fading to a negative number, because roll,\_alpha is random.

try this, see if it works

function fade() {  
roll.onEnterFrame = function() {  
this.\_alpha -= 10;  
if (this.\_alpha\<=0) {  
this.\_alpha = 0;  
delete this.onEnterFrame;  
this.\_parent.gotoAndStop(1);  
}  
};  
}

---

<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 23, 2004, 6:08pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/10 "2004-07-23T18:08:44Z")

</div>

i’ve always wondered what delete this.onEnterFrame does…

🙂

---

<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 23, 2004, 6:09pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/11 "2004-07-23T18:09:53Z")

</div>

i forgot to mention :oops: roll has some actions too.

```auto

onClipEvent(enterFrame){
	this._alpha = 50 + Math.round(Math.random()*40);
}

```

without this code your code works stringy, but then i dont have an changing alpha… so do you have any suggestions?

---

<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 23, 2004, 6:16pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/12 "2004-07-23T18:16:55Z")

</div>

> [@bodyvisual](#):
>
> i’ve always wondered what delete this.onEnterFrame does…
> 
> 🙂

why? is that important? because i dont know what it means…

---

<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 23, 2004, 6:17pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/13 "2004-07-23T18:17:13Z")

</div>

> [@bodyvisual](#):
>
> i’ve always wondered what delete this.onEnterFrame does…
> 
> 🙂

when you use enterFrame, it means something is happening every frame, Even if you cannot see it so it can become heavy on processors.

---

<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 23, 2004, 6:24pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/14 "2004-07-23T18:24:46Z")

</div>

> [@stringy](#):
>
> when you use enterFrame, it means something is happening every frame, Even if you cannot see it so it can become heavy on processors.

try this on the timeline (rather than the clip)  
function fade() {  
roll.onEnterFrame = function() {  
this.\_alpha -= 10;  
if (this.\_alpha\<=0) {  
this.\_alpha = 0;  
delete this.onEnterFrame;  
this.\_parent.gotoAndStop(1);  
}  
};  
}  
roll.onEnterFrame = function() {  
this.\_alpha = 50+Math.round(Math.random()\*40);  
};

---

<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 23, 2004, 6:28pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/15 "2004-07-23T18:28:29Z")

</div>

Thanks a lot!! It works!!

---

<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 23, 2004, 6:38pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/16 "2004-07-23T18:38:17Z")

</div>

> [@2nd day](#):
>
> Thanks a lot!! It works!!

welcome

---

<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 23, 2004, 7:42pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/17 "2004-07-23T19:42:46Z")

</div>

Now i’ve got another function question. I’ve made a new function on the first frame of the movie. here’s the code:

```auto

function move(obj, endx){
	trace(obj);
	trace(endx);
	obj.onEnterFrame = function() {
		speed = 10;
		x = endx - this._x;
		this._x += x/speed;
	}
}

```

and a button with the code

```auto

on(release){
   _root.move("MC", 500);
}

```

The function traced MC and it traced 500 too. But there was no movement, why??

---

<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 23, 2004, 8:05pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/18 "2004-07-23T20:05:20Z")

</div>

> [@2nd day](#):
>
> Now i’ve got another function question. I’ve made a new function on the first frame of the movie. here’s the code:
> 
> ```auto
> 
> function move(obj, endx){
> trace(obj);
> trace(endx);
> obj.onEnterFrame = function() {
> speed = 10;
> x = endx - this._x;
> this._x += x/speed;
> }
> }
> 
> ```
> 
> and a button with the code
> 
> ```auto
> 
> on(release){
> _root.move("MC", 500);
> }
> 
> ```
> 
> The function traced MC and it traced 500 too. But there was no movement, why??

the function looks fine  
if both the mc and button are on the \_root timeline you can just use  
on (release) {  
move(mc, 500);  
}

or if you give the button aninstance name mybutton, on the timeline below the function type  
mybutton.onRelease = function (){  
move(mc,200)  
}  
which is a bit tidier

---

<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 23, 2004, 8:11pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/19 "2004-07-23T20:11:00Z")

</div>

Thanks a lot!! Again! You sure helped me today! Thanks

---

<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 23, 2004, 8:27pm UTC](https://forum.kirupa.com/t/why-dont-you-fade/58565/20 "2004-07-23T20:27:17Z")

</div>

Allright, another problem… this is very hard to explain… so here is the .fla The problem is about the menu collaps back… play with the menu and you’ll see what i mean…

[Next page](https://forum.kirupa.com/t/why-dont-you-fade/58565.md?page=2)
