Little help please

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!

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.

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?

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…

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
      } 
 
 

works on Flash mx 2004 pro …

dont know what version you have… ?

that’s what i’m using.
MX2004 pro.

do you think you could come onto AIM and we could chat?
maybe I can send you my file.

then you must have misplaced it…

best is to create a new frame for these kind of functions (i always do)

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.

hmm strange, using AS2.0 ? 1.0 ?

as 2, but i just tried in AS1 and got the same errors :frowning: