moai
August 25, 2004, 5:48am
1
Im trying to write a global fucntion for button rollOver, rollOut animation.
here’s what I have as of right now.
On the root timeline::
stop();
function buttonFade(fade) {
if (fade) {
this.nextFrame();
} else {
this.prevFrame();
}
};
_root.onEnterFrame = function() {
buttonFade();
};
and then on an invisible button inside the MC with the button animation::
on(rollOver) {
buttonFade(true);
}
on (rollOut, dragOut) {
buttonFade(false);
}
Im still wishy washy on function syntax… so could you tell me where I’m going wrong??
thanks!
RvGaTe
August 25, 2004, 6:00am
2
try prototypes, easy to understand:
MovieClip.prototype.buttonFade = function(fade){
if(fade){
this.onEnterFrame = function(){
this.nextFrame();
}
} else {
this.onEnterFrame = function(){
this.prevFrame();
}
}
}
then on the buttons:
on(rollOver) {
this.buttonFade(true);
}
on (rollOut, dragOut) {
this.buttonFade(false);
}
guess it dozn’t need explaining if you take a good look.
moai
August 25, 2004, 6:07am
3
okay,
I understand everything but movieclip.prototype.
why is that there? and unless its _root isnt that going to break the whole modular idea for the function?
RvGaTe
August 25, 2004, 6:19am
4
its for creating functions that extends objects…
in this case, buttonFade, extends a MovieClip object…
buttonFade is a prototype of a Movieclip…
same as: _root.gotoAndPlay(2);
where gotoAndPlay is a prototype of a Movieclip.
it can be done on different objects, like an array:
Array.sort();
you can create your own:
Array.prototype.functionName = function(vars){}
wich will work on EVERY array…
this will work for all kind of things, including MovieClips
edit: yes, the prototype function needs to be on root…
moai
August 25, 2004, 6:33am
5
entered in the code verbatim, and it spat back 6 errors.
*Error** Scene=Scene 1, layer=a, frame=1:Line 5: Operator '=' must be followed by an operand
**if(fade){
**Error** Scene=Scene 1, layer=a, frame=1:Line 6: Syntax error.
****this.onEnterFrame = function(){
**Error** Scene=Scene 1, layer=a, frame=1:Line 7: Syntax error.
******this.nextFrame();
**Error** Scene=Scene 1, layer=a, frame=1:Line 8: Syntax error.
****}
**Error** Symbol=mc_Bio, layer=Layer 5, frame=1:Line 2: Syntax error.
**this.buttonFade(true);
** Symbol=mc_Bio, layer=Layer 5, frame=1:Line 3: Unexpected '}' encountered
}
RvGaTe
August 25, 2004, 6:36am
6
works on Flash mx 2004 pro …
dont know what version you have… ?
moai
August 25, 2004, 6:39am
7
that’s what i’m using.
MX2004 pro.
moai
August 25, 2004, 6:42am
8
do you think you could come onto AIM and we could chat?
maybe I can send you my file.
RvGaTe
August 25, 2004, 6:43am
9
then you must have misplaced it…
best is to create a new frame for these kind of functions (i always do)
moai
August 25, 2004, 6:46am
10
i put the code on the root in the 1st frame.
i typically code that way, where the main timeline doesn’t move at all… only the movie clips.
the root script is in its own layer.
RvGaTe
August 25, 2004, 6:53am
11
hmm strange, using AS2.0 ? 1.0 ?
moai
August 25, 2004, 7:08am
12
as 2, but i just tried in AS1 and got the same errors