Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : "on Handler" missing?


TC5
6/14/2004 9:59:12 PM
When assigning an action to an instance of a button (getURL or gotoandplay) The
button fails to work. Checking the code reveals an error:

'Statement must appear within on handler"

AFAIK the "on Release" handler should be created automatically when I assign
an action to a button no? This seems to have been the case in a previous movie
I made. Why isn't it doing it now?
Dinghus
6/14/2004 10:23:05 PM
TC5
6/15/2004 2:27:03 AM
mandingo
6/15/2004 3:26:50 AM
You can't put the code directly on the instance.

If it is a button :

on(release){
gotoAndPlay(2);
}

if it is a movieClip :
myClip.onRelease = function(){
gotoAndPlay(2);
}

hope that helps
cheers,
TC5
6/15/2004 1:45:27 PM
David Stiller
6/15/2004 2:38:36 PM
You can put it on the instance. Not sure what mandingo meant. What
action, exactly are you putting on the button? By the sound of your error
message, you must be putting your gotoAndPlay() (or whatever) in there
without wrapping it in an on() handler.

[quoted text, click to view]

You have to type the handler yourself, but it's easy. on() is the
handler, and it accepts a number of events ("release" being on of them), so
....

on(release) {
// your code here
}

Keep in mind, this on() business only works when the script is attached
to the instance. I personally prefer the name-your-instance approach also
in mandingo's post. If you give your button (or movie clip) instance a
name, then you can "call it" by name and tell it what to do from the main
timeline -- that is, from a frame script. To me, it's nicer that way,
because you don't have to go hunting for your code later, as it's all there
in (possibly) frame 1.


David
stiller ( at ) quip ( dot ) net



[quoted text, click to view]
put the action on the button itself.

David Stiller
6/15/2004 4:54:34 PM
Maybe that was back in the Normal mode vs. Expert mode days, when Flash
optionally wrote all sorts of code for you. Nowdays, it's Expert mode only.

In any case, I'm glad that all made sense to you. :) Happy coding.


David
stiller ( at ) quip ( dot ) net

[quoted text, click to view]
manually in the past... Maybe I'm mistaken.

TC5
6/15/2004 8:05:08 PM
Thanks David for your input.

mandingo
6/15/2004 10:46:15 PM
Yeah, well I just re-read what I wrote... not very clear at all sorry... was a
long day.

What I meant was that you can't just put it by itself on the instance like
that. In the case of a button, the code appears on the button instance with
the on(release) event handler as I provided.

And for the movieClip, the code appears on an Actions layer with the
myClip.onRelease = function(){}

sorry for the unclear previous post

cheers,

AddThis Social Bookmark Button