on(release) {...} or myButton.onRelease = function() {...} - action script 2 issues

Joshc picture Joshc · Oct 2, 2012 · Viewed 73.9k times · Source

I am having real confusion with some flash banners I'm creating and making the button into a clickable object which opens a web page.

I have been using this code for a while below, which works...

on(release){
    getURL("http://www.the-dude.co.uk", "_blank");
}

And I placed this code on actual button within the actions panel


However I have been told the code above is very old and that I should use action script like below...

buttonInstance.onRelease = function() {
    getURL("http://www.the-dude.co.uk", "_blank");
}

So I've tried to get this method below to work but nothing happens when I click the button, and I get one error, this...

Scene=Scene 1, layer=button, frame=1, Line 1 Statement must appear within on handler

So in a nutshell I cannot get this newer code to work! Ahh


Can anyone please help me understand where I am going wrong?

I have tried placing the new code in the Scene 1 of my actions. No worky..

And I've also tried placing the code below, actually on my button within the actions panel...

this.onRelease = function() {
    getURL("http://www.the-dude.co.uk", "_blank");
}

Still not working.


My scene settings are alway this...

enter image description here


Any help would be great thanks.

Answer

jtmayer picture jtmayer · Oct 2, 2012

You need to place the code below on the same timeline as the instance of the button (as you tried). And the instancename of the button must be "buttonInstance".

You can set the instance name in the properties panel when the button is selected.

buttonInstance.onRelease = function() {
    getURL("http://www.the-dude.co.uk", "_blank");
}