# Forcing onrelease behavior

**URL:** <https://forum.kirupa.com/t/forcing-onrelease-behavior/186867>\
**Category:** Uncategorized\
**Created:** [April 25, 2006, 3:31am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867 "2006-04-25T03:31:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![veraxoxo](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@veraxoxo](https://forum.kirupa.com/u/veraxoxo)\
**Post date:** [April 25, 2006, 3:31am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/1 "2006-04-25T03:31:47Z")

</div>

How do a call a button’s on release behavior via actionscript? i.e. without the user pressing the button, I want to call the code that is within the onrelease function of that button.

I’ve tried  
button.onRelease;

and  
button.onRelease();

but it does not call the function.

---

<div class="post-metadata">

**Author:** ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)\
**Post date:** [April 25, 2006, 3:39am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/2 "2006-04-25T03:39:17Z")

</div>

button.onRelease(); should work. hmm… can you post our code? maybe a scope issue.

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 25, 2006, 3:44am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/3 "2006-04-25T03:44:28Z")

</div>

What you can do, is have the actuall button call a function onpress.

Instead of this:

ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#0000ff]button[/COLOR].[COLOR=#0000ff]onRelease[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]\</p\>  
\<p\> [COLOR=#808080]_//do something\</p\>_[/COLOR]  
\<p\>[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

Do this:

```auto
function pressthebutton(){
//do something
}
button.onPress = function(){
pressthebutton();
}
//then you could later say for example:
pressthebutton();
//or
loadmovieorsomething.onLoad = function(){
pressthebutton();
}
```

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 25, 2006, 3:45am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/4 "2006-04-25T03:45:58Z")

</div>

try using an actual function:

```auto

function pressthebutton(){
//do something
}
button.onPress = function(){
pressthebutton();
}
//then you could later say for example:
pressthebutton();
//or
loadmovieorsomething.onLoad = function(){
pressthebutton();
}

```

---

<div class="post-metadata">

**Author:** ![Mirandir](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Mirandir](https://forum.kirupa.com/u/Mirandir)\
**Post date:** [April 25, 2006, 11:01am UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/5 "2006-04-25T11:01:03Z")

</div>

How have you applied the onRelease on your button? If it’s a plain “on(release)” you cannot call it as “button.onRelease”. You must have set the eventhandler as a callback like this:

```auto

button.onRelease = function()
{
    trace("Yeah! You clicked me!")
}

```

/Mirandir

---

<div class="post-metadata">

**Author:** ![veraxoxo](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@veraxoxo](https://forum.kirupa.com/u/veraxoxo)\
**Post date:** [April 25, 2006, 12:30pm UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/6 "2006-04-25T12:30:33Z")

</div>

> [@Defective](#):
>
> try using an actual function:
> 
> ```auto
> 
> function pressthebutton(){
> //do something
> }
> button.onPress = function(){
> pressthebutton();
> }
> //then you could later say for example:
> pressthebutton();
> //or
> loadmovieorsomething.onLoad = function(){
> pressthebutton();
> }
> 
> ```

Yes, I’ll do this if I can’t figure out the direct call to the button’s onRelease. Thanks!

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 25, 2006, 1:27pm UTC](https://forum.kirupa.com/t/forcing-onrelease-behavior/186867/7 "2006-04-25T13:27:26Z")

</div>

> [@Defective](#):
>
> try using an actual function:

onRelease is almost always an actual function 😉

You shouldn’t have any problems calling it, post your code 🙂
