i need some help writing a reusable function as im not too sure on the syntax of it all. basically i wrote this script for a movie clip but i want to use it on more than one, but i dont want to have to re write it over and over for each instance.
awesome, thanks so much! ive got one more question: what does prototype do, is it something that just lets flash know that the script is reusable? also, dont i have to specify an onEnterFrame command with this? i guess ill just try it and find out…
every function is re-usable. Its just a matter of… using it.
A prototype that is a special function that can be called using this.functionName as long as the this is of the type of object the prototype was create. ahmed’s example is a movieclip prototype so any movieclip can just say this.myMCFunction() and run that function. For non-prototype functions, you would have to properly reference and target the function correctly based on where you wrote it. For example, if you wrote it in root as just funcName = function(){ then whenever you called it you would have to say _root.funcName();
Take a nother look at ahmed’s function and copy and paste it into your movie again. It should work right. … note, however, the move variable must be the move variable IN that movieclip
thanks for your reply. ive tried what you suggested and its still not working. perhaps it is the way i have set everything up. for instance, i have my functions on the root timeline (note: im not using ahmed example in this…):
basically this would just allow the movieclip to animate forwards and backwards depending on how long the mouse was over the movieclip. normally if i had lots of movieclips using this same idea i would have to rewrite the function as:
…function(){
if(move2)
…
}
…function(){
if(move3)
…
}
and on each movieclip i’d put:
(rollOver){
_root.move2 = true;
}
(rollOver){
_root.move3 = true;
}
etc
etc
for as many buttons as i need. does that make sense? i hope so. i was hoping i could just create one “generic” function that i could call from each movieclip. the other thing was on ahmeds AS theres no part in the function that specifies the onEnterFrame command, shouldnt’ that be a part of it someplace? as you can probably tell my actionscript skills are pretty basic so please forgive me if im missing something blatently obvious.
basically, you declare the onRollOver, onRollOut, onDragOut and onEnterFrame for all movies through a loop… inside the onEnterFrame function, the prototype ‘myMCFunction’ is called…
once again thanks for all your help. ive found a simpler way around what i was trying to accomplish but your suggestions have given me much insight into new ideas. thank you.