# Function problem

**URL:** <https://forum.kirupa.com/t/function-problem/20490>\
**Category:** Uncategorized\
**Created:** [May 9, 2003, 4:11am UTC](https://forum.kirupa.com/t/function-problem/20490 "2003-05-09T04:11:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bongoman](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@bongoman](https://forum.kirupa.com/u/bongoman)\
**Post date:** [May 9, 2003, 4:11am UTC](https://forum.kirupa.com/t/function-problem/20490/1 "2003-05-09T04:11:32Z")

</div>

Hi there

I’m having trouble with a function and an onRelease event handler that calls it.

The code goes like this:

function setAlpha(clip, value){

\_root.clip.\_alpha = value;

}

Then the function gets called like this:

\_root.chp1\_btn.onRollOver = setAlpha(chp1\_mc, 50);

What I am finding is that the function is not working properly. THe function sort of executes without waiting for the event handler to trigger it.

If I put a trace(“hello”); command in the function, it traces instantly when I test the movie. I want the function to wait until I rollover chp1\_btn instance.

Any clues as to what I am missing would be greatly appreciated.

BOngoMan

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2003, 6:28am UTC](https://forum.kirupa.com/t/function-problem/20490/2 "2003-05-09T06:28:00Z")

</div>

bongoman:  
Change your code:

_\_root.chp1\_btn.onRollOver = setAlpha(chp1\_mc, 50);_

to:

chp1\_btn.onRollOver = function() {  
setAlpha(chp1\_mc, 50);  
}

Hope it helps! :thumb:

Cheers!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2003, 8:29am UTC](https://forum.kirupa.com/t/function-problem/20490/3 "2003-05-09T08:29:49Z")

</div>

Thank you - that worked!

But why? I’m trying to really understand actionscript: why was my earlier code wrong?

Cheers

Bongoman

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2003, 8:58am UTC](https://forum.kirupa.com/t/function-problem/20490/4 "2003-05-09T08:58:00Z")

</div>

I am new to Flash MX but as far as I am concerned and understood, InstanceName.onRollover, or InstanceName.onEnterframe, etc. are reserved commands that works the same as onClipEvent… err… hehehe… hope i’m right… Therefore, instead of using onClipEvent command, you use in one frame:  
\_root.instanceName.onEnterframe = function() {  
… your commands…  
}

\_root.instanceName.onRollover = function() {  
… your commnds…  
}  
etc…

Hope it helps. Hehehe… 🙂
