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

flash actionscript : Easiest way to program buttons?



HannaB
8/17/2004 9:24:21 PM
I can't seem to find any tutorial that shows something as simple as how to tell
a button to go one frame forward and stop. Every tutorial I try has different
menu options under the "+" in the Actions panel from what I have in MX 2004. I
need something that shows a list of mouse events etc. and I just can't find
that anywhere!!!

Every time I try to copy a code that "should" work: (i.e.
on (press) {
gotoAndStop(nextFrame);
}
}
, I get error messages like "Statement must appear within on handler" and my
buttons don't go anywhere :-(

Thankful for any help.

//Hanna
pwiop
8/17/2004 11:05:08 PM
Hi Hanna

If you have abutton on the stage and give it an instance name, say b1 you can
basically code it in one of two ways.
1 - put the code on the maintimeline refering to the button
2 - put the code on the button instance (ie select the code then add the code)
The first method requires you refer to the button by name thus:
b1.onRelease = function() {
play();
};
The second method, ie having the button selected is thus;
on (release) {
play();
}
In the second case you do not need to name the button.
If you put the first piece of actionscript directly on the button, or the
second piece on the timeline, Flash would return an error message

p a u l
HannaB
8/18/2004 4:03:48 PM
Hi Paul and thanks for your reply.
I'm still puzzled, though. What if I want one button that steps one frame
forward and one button that steps one frame backwards. Where do I put
"nextFrame" resp. "prevFrame" in the code you gave me. And how does "it" know
to go one frame and then stop? I didn't see GotoAndStop in the code you wrote.
This is driving me nuts, simply because I can't find any helpful hints in Flash
tutorials etc.

Thankful for more help!
//Hanna
Erzek
8/18/2004 4:31:15 PM
Make two layers, one with your two buttons and the other layer with two
keyframes. Name the first layer "buttons" and the second "content".

Click on the first keyframe of the buttons layer and put this code:

stop();

Click on the first keyframe of the "content" layer and draw a circle, in the
second keyframe of this layer draw a rectangle.

Now go to your buttons layer and click on the first button and put this code:

on (press) {
this.nextFrame();
}

Do the same with the second button but change this.nextFrame(); to
this.prevFrame();

Ek
AddThis Social Bookmark Button