Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : how do you control a button release from a frame script?


David Stiller
2/10/2006 1:34:49 PM
[quoted text, click to view]

That's right. The button symbol (which is an instance of the Button
class) raises its own event. It's not code, but the user who triggers a
button release -- by letting go of the button. ;)

Here's how it works. Everything in ActionScript is an object. Objects
are defined by classes, which are like blue prints or recipes for objects.
So your button symbol, even though you drew the artwork yourself, is a
Button instance. You give that instance an instance name via the Properties
inspector. Just click the button to select it, then supply an instance
name. If you like, call it myButton, but you can also call it
mozartSmellyPants, jellyBean, or whatever. The instance name you choose is
your "handle" to the object created by the Button class (this holds true for
any class instance, including text fields, movie clips, and so on).

Look up the "Button class" entry in the ActionScript Language Reference
(not the Components Language Reference, which features its own Button).
You'll see everything a button can do listed under Methods, all the
characteristics it has under Properties, and all the things it can react to
under Events. So in your code, just swap out the Button class name with the
instance name you chose. If it's myButton (that is, if the instance name
field in the Properties inspector says "myButton" while you select this
button) ...

myButton.onRelease = function() {
}

.... this assigns a function to that button's onRelease event. You'll see in
the Button class under Events that onRelease is one of your available
choices. The above script would go in a keyframe, *not* on the button.
Then whatever you put inside the curly braces, {}, of that function, will be
carried out when someone clicks, then lets go, of this particular Button
instance.

Your original sample code ...

[quoted text, click to view]

.... makes no sense, for a number of reasons. First, you're creating a
function called processText. Actually, you're creating a variable that
points to such a function. But you're not *calling* the function from
anywhere. Second, all this function does is invoke a release() method of a
Button instance. But if you check the Button class entry, you won't see a
method called release().

In order for a function to do something, it must be called -- must be
triggered. The Button.onRelease event *occurs* when the user clicks, then
releases, a button. This is called an event. When the event occurs, you're
telling a certain function to be triggered. In my sample code above, that's
what's going on. The user causes the event to occur, and the event triggers
a function.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
2/10/2006 3:16:08 PM
[quoted text, click to view]

Aha. I didn't read it that way. If that's it, then no ...
unfortunately, it won't work that way -- *if* that release handler is
assigned via on(), and I'm betting it is. See, nothing has been assigned to
the Button instance's onRelease handler, which is a different thing.
(Shouldn't be, but it is. I really wish there was a way to flush all those
on() tutorials out of the Internet, or at least mark them as legacy.)

The OP will have to assign a function to the button's onRelease event in
the non-on() (and much better, all around!) fashion. Then he/she can
trigger that puppy at will.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

NodeNode
2/10/2006 3:56:38 PM
I need to call a button release from a frame script...

I tried this

processText = function(){

myButton.release();

}

but it's not calling the button. The button is in the same frame as the
script, so what gives?...
thanks
blemmo
2/10/2006 4:06:04 PM
Use myButton.onRelease(), that should do it.

cheers,
NodeNode
2/10/2006 4:48:24 PM
blemmo
2/10/2006 7:01:47 PM
As I understood your problem, you have a button with some onRelease Event, and
want to trigger that from a Frame. Is that right?
If yes, the first suggestion should work. It would call the methods that are
written in the onRelease code. I used that before and it worked fine for me.
If your problem is of another nature, or you didn't solve it with David's
suggestions, then please explain it again.

cheers,
blemmo
NodeNode
2/11/2006 4:21:10 PM
thank you Blemmo and David,

I don't know WTF was going on before, but i have it working now, with both

myButton.onRelease();

and

myButton.onRelease = function(){
gotoAndPlay("makeLove_NotWar");
}

thanks for all the feedback
- nodeNode
AddThis Social Bookmark Button