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

Coding for addition using if / and statements

Engaged ,
Dec 17, 2014 Dec 17, 2014

I have to create an app out of a Flash project the project is simple. Its like a book with each page having a set of buttons ( 3 buttons per page)

each button is actually an answer which there are three choices. AS the viewer chooses one answer from each page I need the correct answers coded so when they ad up to 1000 or whatever number and OVER that will trigger a new page with certain info. If the total is UNDER 1000 then that will trigger a different page to open.

Was wondering how I go about coding this?

any help?

R

TOPICS
ActionScript
223
Translate
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
LEGEND ,
Dec 17, 2014 Dec 17, 2014

Have each of your buttons add its value to a number variable and use the number variable to detemine whether 1000 is reached or not.

Translate
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
Engaged ,
Dec 17, 2014 Dec 17, 2014

thanks for that but how do I code I believe its an integer?

so if 3 buttons on one page do I code each button on each page or create a variable for each page as the total of the variable must be calculated at the end of the book, follow?

Translate
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
LEGEND ,
Dec 17, 2014 Dec 17, 2014

var totalValue:int = 0;

There are too many details you have left out for me to determine what you need to do, but you should be able to reason it out based on the question you just asked.   If the variable needs to be used at the end then create one variable and share it for each page so that at the end it represents the sum of all pages.

Each button needs to be coded regardless of where they are.

Translate
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
Engaged ,
Dec 17, 2014 Dec 17, 2014

Thanks so much for your help as I haven't used Flash in a while but basically what I need to do is the following pr page.

PAGE 1

button One -correct answer

button two - incorrect answer

button three - incorrect answer

PAGE 2

button One -correct answer

button two - incorrect answer

button three - incorrect answer

25 pages in all

none of this correct or incorrect info displays anywhere it is just carried over to the next page where the actions are the same, then at the end the total gets added up and based on that will trigger an event, follow?

I need to really brush up on AS3 but don't know nearly enough to code this without any help.

Translate
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
LEGEND ,
Dec 17, 2014 Dec 17, 2014
LATEST

You will need to show some work to get help with it.  For now, here's a starter for making a button work...

Let's say you create a button symbol.  Since it is a button, it is already a self animating object that will react to mouse interactions, but only visually at this stage.  The first thing you need to do to make it useful code-wise is to assign it a unique instance name.  So you drag a copy of it out to the stage from the library, and while it's still selected, you enter that unique instance name for it in the Properties panel... let's say you name it "btn1"


In AS3, to make a button work with code, you need to add an event listener and event handler function for it.  You might need to add a few (for different events, like rollover, rollout, clicking it, but for now we'll just say you want to be able to click it to add a value to a variable.  In the timeline that holds that button, in a separate actions layer that you create, in a frame numbered the same as where that button exists, you would add the event listener:


btn1.addEventListener(MouseEvent.CLICK, btn1Click);

The name of the unique function for processing the clicking of that button is specified at the end of the event listener assignment, so now you just have to write that function out:


function btn1Click(evt:MouseEvent):void {

     totalValue += 10;

}

Translate
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