Forcing onrelease behavior

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.

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

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:

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

try using an actual function:


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

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:


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

/Mirandir

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

onRelease is almost always an actual function :wink:

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