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…
What’s my problem?
system
July 23, 2004, 4:32pm
2
you have to call the function. right after that code put _root.fade();
then it will work.
system
July 23, 2004, 5:18pm
3
how do I have to do that… i’m not very formiliar with this function code… :S
system
July 23, 2004, 5:19pm
4
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();
system
July 23, 2004, 5:21pm
5
But that is what i do, when i rollout.
on(rollOut){
this.fade();
}
system
July 23, 2004, 5:24pm
6
And it also traces “boe”, as i have difined in my function… so i has to be a function-problem, right?
system
July 23, 2004, 5:28pm
7
is it just fading to 0? you did use a while loop…
system
July 23, 2004, 5:33pm
8
it’s fading to a negative number, because roll,_alpha is random.
system
July 23, 2004, 6:04pm
9
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);
}
};
}
system
July 23, 2004, 6:08pm
10
i’ve always wondered what delete this.onEnterFrame does…
system
July 23, 2004, 6:09pm
11
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?
system
July 23, 2004, 6:16pm
12
why? is that important? because i dont know what it means…
system
July 23, 2004, 6:17pm
13
when you use enterFrame, it means something is happening every frame, Even if you cannot see it so it can become heavy on processors.
system
July 23, 2004, 6:24pm
14
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);
};
system
July 23, 2004, 6:28pm
15
Thanks a lot!! It works!!
system
July 23, 2004, 7:42pm
17
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??
system
July 23, 2004, 8:05pm
18
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
system
July 23, 2004, 8:11pm
19
Thanks a lot!! Again! You sure helped me today! Thanks
system
July 23, 2004, 8:27pm
20
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…