Copy link to clipboard
Copied
I need to use Flash for a uni assignment, I have just started using Flash so this is a beginner question.
For my assignment I need to create a bouncing ball animation and then add stop and start buttons. So I created the buttons by drawing rectangles and then converted it to a symbol and made it a button. I have tried all the coding snippets that I can find and most of the time comes up as a 1086 Syntax error. The coding I've been using is:
For the play button:
on(release){
play();
}
For the stop button:
on(release){
stop();
}
Can you please tell me what I'm doing wrong?
1 Correct answer
funtion should be function
Copy link to clipboard
Copied
with as3, you can't attach code to objets:
your_btn.addEventListener(MouseEvent.CLICK,playF)
your_btn.addEventListener(MouseEvent.CLICK,stopF);
function playF(e:MouseEvent):void{
this.play();
}
function stopF(e:MouseEvent):void{
this.stop();
}
Copy link to clipboard
Copied
Thank you for your reply kglad,
I still however can't get it to work.
I am using the button from the Flash library, then I right click on them and say 'convert to symbol', there I give it a name and choose button. After that I right-click on the first frame of the button and choose 'Actions' then I put in the code:
import flash.events.MouseEvent;
startbtn.addEventListener(MouseEvent.CLICK,playF)
function playF(e:MouseEvent):void{
this.play();
}
(the first line Flash puts in itself) does this have something to do with my process of creating the button or is the coding I put in still wrong?
Copy link to clipboard
Copied
click the button that's on your stage.
check the properties panel
enter startbtn in the name field
Copy link to clipboard
Copied
yes, kglad, my button's instance name is startbtn which is why I changed the code you gave me from "your_btn" to "startbtn".
It is still not working however. I have used other codes to make it work before but then I didn't convert it to a button so the button was a movie clip, but I need to convert it to a button because I need it to have a click sound when you press it. But it seems that all my problems start when I convert the buttons into buttons, by going to "convert to symbol" then choose button. When I preview the movie a "1086: Syntax error: expexting semicolon before rightparen" message shows.
Any solutions for this problem?
Copy link to clipboard
Copied
click file>publish settings and tick 'permit debugging'. retest.
the line number with your error will be in the error message. if it's not obvious to you how to fix the problem, copy and paste the line of code with the error.
Copy link to clipboard
Copied
It says:
Location:
Scene 1, Layer 'Start Button', Frame 1, Line 2
Description: 1071: Syntax error: expected a definition keyword (such as function) after attribute function, not playF.
this is the code:
startbtn.addEventListener(MouseEvent.CLICK,playF)
funtion playF(e:MouseEvent):void{
this.play();
}
Copy link to clipboard
Copied
funtion should be function
Copy link to clipboard
Copied
It gave me another error message that said, that the library button cannot be converted into a button. So I created a button and now it works.
Thanks for your help!
Copy link to clipboard
Copied
you're welcome.

