# Little help please

**URL:** <https://forum.kirupa.com/t/little-help-please/120532>\
**Category:** Uncategorized\
**Created:** [August 25, 2004, 5:48am UTC](https://forum.kirupa.com/t/little-help-please/120532 "2004-08-25T05:48:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 5:48am UTC](https://forum.kirupa.com/t/little-help-please/120532/1 "2004-08-25T05:48:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [August 25, 2004, 6:00am UTC](https://forum.kirupa.com/t/little-help-please/120532/2 "2004-08-25T06:00:55Z")

</div>

try prototypes, easy to understand:

```php

MovieClip.prototype.buttonFade = function(fade){
  if(fade){
    this.onEnterFrame = function(){
      this.nextFrame();
    }
  } else {
    this.onEnterFrame = function(){
      this.prevFrame();
    }
  }
}

```

then on the buttons:

```php

on(rollOver) {
  this.buttonFade(true);
}

on (rollOut, dragOut) {
  this.buttonFade(false);
}

```

guess it dozn’t need explaining if you take a good look.

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 6:07am UTC](https://forum.kirupa.com/t/little-help-please/120532/3 "2004-08-25T06:07:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [August 25, 2004, 6:19am UTC](https://forum.kirupa.com/t/little-help-please/120532/4 "2004-08-25T06:19:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 6:33am UTC](https://forum.kirupa.com/t/little-help-please/120532/5 "2004-08-25T06:33:41Z")

</div>

entered in the code verbatim, and it spat back 6 errors.

```auto

 *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
      } 
 
 

```

---

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [August 25, 2004, 6:36am UTC](https://forum.kirupa.com/t/little-help-please/120532/6 "2004-08-25T06:36:41Z")

</div>

works on Flash mx 2004 pro …

dont know what version you have… ?

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 6:39am UTC](https://forum.kirupa.com/t/little-help-please/120532/7 "2004-08-25T06:39:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 6:42am UTC](https://forum.kirupa.com/t/little-help-please/120532/8 "2004-08-25T06:42:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [August 25, 2004, 6:43am UTC](https://forum.kirupa.com/t/little-help-please/120532/9 "2004-08-25T06:43:09Z")

</div>

then you must have misplaced it…

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

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 6:46am UTC](https://forum.kirupa.com/t/little-help-please/120532/10 "2004-08-25T06:46:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [August 25, 2004, 6:53am UTC](https://forum.kirupa.com/t/little-help-please/120532/11 "2004-08-25T06:53:35Z")

</div>

hmm strange, using AS2.0 ? 1.0 ?

---

<div class="post-metadata">

**Author:** ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)\
**Post date:** [August 25, 2004, 7:08am UTC](https://forum.kirupa.com/t/little-help-please/120532/12 "2004-08-25T07:08:07Z")

</div>

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