-
1. Re: Flash Newbie; Button Code Difficulities
Ned Murphy Mar 13, 2012 7:22 PM (in response to Federal Blue)It's easier to read code when you follow the more standard format....
Button1.addEventListener(MouseEvent.CLICK,ClickHandler);
function ClickHandler(evt:MouseEvent):void{
gotoAndPlay(3);
}
Yes, if you have a button that you place on the stage and assign an instance name of Button1 to it (via the properties panel) then the code shown above should cause the timeline it is sitting in to start playing at frame 3.... just notice that I have changed the argument type in the event handler function to indicate it is being passed a MouseEvent.
Aother standard is that you only start names with capital letrters if they are class names, like MouseEvent, Object, etc. So normally you would name your button with a lower case letter, as well as the event handler function or any variables that you add to the code.
-
2. Re: Flash Newbie; Button Code Difficulities
Federal Blue Mar 14, 2012 4:26 AM (in response to Ned Murphy)Thanks for the help so far, I've went ahead and lowercased all layers and buttons, just in case. So I have this code below in a layer labeled script, for all my coding to go into. Both pieces are in the same frame, frame 2. I also tried separating them, so that the button code went into the layer where the button was, but nothing seemed to work.
gotoAndPlay(1);
block1.addEventListener(MouseEvent.CLICK,ClickHandler);
function ClickHandler(evt: MouseEvent):void{
}
I also made sure that the button was correctly spelled as block1, and so was the layer. Is there a step that I am missing?
-
3. Re: Flash Newbie; Button Code Difficulities
Ned Murphy Mar 14, 2012 4:44 AM (in response to Federal Blue)What you name layers has no relevance to code, so feel free to name them for your own benefit as the designer.
For the code you show, you have nothing in the function, so it isn't going to do anything.
If you just said you have this same code in frames 1 and 2, that is not something you want to do. I am still not clear on why you are bouncing between frames 1 and 2, but if there is a reason for it I would put the gotoAndPlay(1) only in frame 2 and just have the rest of that code only in frame 1.
The button's instance name "block1" should be assigned in the Properties panel where you see a textfield with <Instance Name> in it.


