PDA

View Full Version : CS3 - Attach simple code to buttons


d000hg
09-08-2008, 10:33 AM
Say I have a symbol MyButton, as a button with the 4 special frames. When you mouse-over/mouse-out an instance, I'd like another object to be affected... text in some text box changing, or the item becoming visible, or similar.
I know AS3 but I'm a real noob at CS3. I don't really get how actions work in CS3.

snickelfritz
09-09-2008, 04:39 AM
Use movieclips instead of button symbols.
Movieclips are far more versatile.

Basic framenav FLA is attached.

d000hg
09-09-2008, 08:49 AM
That's really cool, I appreciate it.

One quick question, is it possible to actually set code on frames of individual buttons? Or do you have to set code for frames of a symbol/layer and work it out that way?

snickelfritz
09-09-2008, 09:41 AM
I'm not sure I'm following your question.
Yes, you can create an actions layer within a movieclip symbol that references itself and/or objects nested within itself.

for example, the following rollover/rollout/properties code can be nested in the timeline of a movieclip button.
The button will then be completely portable, and all instances will have these properties.
stop();
import gs.TweenMax;
import gs.easing.*;

this.mouseEnabled = true;
this.buttonMode = true;
this.mouseChildren = false;

this.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
this.addEventListener(MouseEvent.MOUSE_OUT, btnOut);

function btnOver(event:MouseEvent):void
{
TweenMax.to(this, .2, {tint:0xFFFFFF});
}

function btnOut(event:MouseEvent):void
{
TweenMax.to(this, .2, {removeTint:true});
}

d000hg
09-09-2008, 09:50 AM
Say I have 4 buttons and I want them all to do different things. My question is, can I create a MyBtn symbol, add 4 instances to my stage, and then add code to each instance?
Or do I have to create 4 symbols MyBtn1, MyBtn2, MyBtn3, MyBtn4, add code to the timeline of each symbol, and create one instance of each?

snickelfritz
09-09-2008, 11:00 AM
Say I have 4 buttons and I want them all to do different things. My question is, can I create a MyBtn symbol, add 4 instances to my stage, and then add code to each instance?
Or do I have to create 4 symbols MyBtn1, MyBtn2, MyBtn3, MyBtn4, add code to the timeline of each symbol, and create one instance of each?

Your buttons should virtually always be instances of a single movieclip symbol from the library.
ie: you create movieclip symbol for your button design; all of your buttons are instances of this movieclip.
Each instance should have a unique instance name.
You will reference the symbols by their instance name in your actionscript.
(usually on frame1 in the actions layer)

Use a switch to assign unique behaviors to your buttons.
For example, you might want button1 to rollover purple, button2 to rollover red, etc...

FLA attached.