Why don't you fade?

Hi,

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

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:

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…:frowning:

What’s my problem?

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

then it will work.

:slight_smile:

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

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();

:slight_smile:

But that is what i do, when i rollout.


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

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

is it just fading to 0? you did use a while loop… :slight_smile:

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);
}
};
}

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

:slight_smile:

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


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?

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

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);
};

Thanks a lot!! It works!!

welcome

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


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


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

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

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…