• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Flash CS6 start and stop button coding AS3??

New Here ,
Oct 12, 2016 Oct 12, 2016

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?

TOPICS
ActionScript , Code , How to

Views

7.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 18, 2016 Oct 18, 2016

funtion should be function

Votes

Translate

Translate
Community Expert ,
Oct 12, 2016 Oct 12, 2016

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();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2016 Oct 12, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2016 Oct 13, 2016

Copy link to clipboard

Copied

click the button that's on your stage.

check the properties panel

enter startbtn in the name field

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2016 Oct 17, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2016 Oct 18, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2016 Oct 18, 2016

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();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2016 Oct 18, 2016

Copy link to clipboard

Copied

funtion should be function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2016 Oct 18, 2016

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2016 Oct 18, 2016

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines