View Full Version : do some stuff if button is clicked
s0cket
11-26-2010, 02:26 PM
I know this is really basic, but I need to know how to do it in AS 2. In other languages I would write something like:
if (button.ispressed)
{
do some stuff;
}
But I don't know how to do it in AS properly.(I need it exactly with if statement, not button.onrelease)
orange gold
11-26-2010, 07:08 PM
In AS 2.0
in your main frame (I favor this style of code more, it has less limit to capabilities):
button.onPress = function() {
//do some stuff
}
or inside the button (this style of code is used by beginners to all coding, not just beginners to Flash, since you have coding experience I suggest you learn to code on frames rather than inside of things.. it lets you keep track of everything in one spot.):
on (press) {
//do some stuff
}
or inside a movie clip (same style as inside a button):
onClipEvent (press) {
//do some stuff
}
s0cket
11-26-2010, 10:02 PM
thanks for the answer,and the tip :)
EDIT: still not exactly what I was looking for :/
neilmmm
11-27-2010, 03:15 PM
try this (http://tutorials.learnflash.com/tutorials/flash/button_actions.html)
s0cket
12-03-2010, 10:13 AM
ah, dammit.I thought I will be able to figure it out myself but I just can't. So I got this piece of code:
if (Key.isDown(_root.p1r) || Key.isDown(_root.p1rCase))
{
and I need to change it so instead of checking keyboard keys it checks if button in flash is pressed. How do I do that?The problem is that function doesn't start there and doesn't end after } it keeps on going with if's.
s0cket
12-11-2010, 09:43 PM
Uh..after some time I finally figured how to do equivalent of this in flash. Anyway, somewhere(probably in the layer your buttons are) write this:
button1variable = 0;
button1.onPress = function() {
button1variable = 1;
}
button1.onRelease = function() {
button1variable = 0;
}
now when you want to check if button is pressed somewhere in the script write:
if(button1variable == 1)
{
//stuff goes here
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.