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

Help on equation solving app!

New Here ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

I am trying to make an app to help my students solve simple equations.  I want them to be able to input the necessary parts of an equation then be able to touch a button to reveal what each of the next steps would look like.  The design is terrible right now, I'm trying to get it functioning then worry about how it looks later.  It was moving along nicely but now I have hit a snag.  It works perfectly through the first step.  However, once I add the stuff to the performsecondstep function, I can't enter text into the text boxes at the begginning anymore.  I'm not sure of the problem.  I will post the code from when it works and then when it won't let me input text anymore.

Works fine,

import flash.text.TextFieldType;

onestepbtn.addEventListener(MouseEvent.CLICK, setonestep);

twostepbtn.addEventListener(MouseEvent.CLICK, settwostep);

firststepbtn.addEventListener(MouseEvent.CLICK, performfirststep);

var operator:String = new String;

var constant1:int = new int;

var answer:int = new int;

operator11.visible = false;

constantused1.visible = false;

constantused2.visible = false;

secondstepbtn.visible = false;

operator12.visible = false;

answeroutput.visible = false;

var constantinputtext:String = new String;

var answerinputtext:String = new String;

var operatorinputtext:String = new String;

operatorinput.restrict = "+\\-";

function setonestep(e:MouseEvent):void {

   

}

function settwostep(e:MouseEvent):void {

   

}

function performfirststep(e:MouseEvent):void {

    constantinputtext = constantinput.text;

    answerinputtext = answerinput.text;

    operatorinputtext = operatorinput.text;

    operator11.visible = true;

    operator12.visible = true;

    constantused1.visible = true;

    constantused2.visible = true;

    secondstepbtn.visible = true;

   

    if (operatorinput.text == "+") {

        operator11.text = "-";

        operator12.text = "-";

    } else {

        operator11.text = "+";

        operator12.text = "+";

    }

   

   

    constant1 = int(constantinputtext);

    answer = int(answerinputtext);

    constantused1.text = constantinputtext;

    constantused2.text = constantinputtext;

    firststepbtn.removeEventListener(MouseEvent.CLICK, performfirststep);

    operatorinput.type = TextFieldType.DYNAMIC;

    constantinput.type = TextFieldType.DYNAMIC;

    answerinput.type = TextFieldType.DYNAMIC;

    secondstepbtn.addEventListener(MouseEvent.CLICK, performsecondstep);

}

function performsecondstep(e:MouseEvent):void {

    answeroutput.visible = true;

    answeroutput.text = "hello";

}

This has dummy code for performsecondstep function.  When I actually put stuff in the function, I lose the ability to input text at the beginning of the program.  Not sure as to why.

import flash.text.TextFieldType;

onestepbtn.addEventListener(MouseEvent.CLICK, setonestep);

twostepbtn.addEventListener(MouseEvent.CLICK, settwostep);

firststepbtn.addEventListener(MouseEvent.CLICK, performfirststep);

var operator:String = new String;

var constant1:int = new int;

var answer:int = new int;

operator11.visible = false;

constantused1.visible = false;

constantused2.visible = false;

secondstepbtn.visible = false;

operator12.visible = false;

answeroutput.visible = false;

step2x.visible = false;

step2equals.visible = false;

var constantinputtext:String = new String;

var answerinputtext:String = new String;

var operatorinputtext:String = new String;

var isPlus:Boolean = new Boolean;

isPlus = true;

operatorinput.restrict = "+\\-";

function setonestep(e:MouseEvent):void {

   

}

function settwostep(e:MouseEvent):void {

   

}

function performfirststep(e:MouseEvent):void {

    constantinputtext = constantinput.text;

    answerinputtext = answerinput.text;

    operatorinputtext = operatorinput.text;

    operator11.visible = true;

    operator12.visible = true;

    constantused1.visible = true;

    constantused2.visible = true;

    secondstepbtn.visible = true;

   

    if (operatorinput.text == "+") {

        operator11.text = "-";

        operator12.text = "-";

    } else {

        operator11.text = "+";

        operator12.text = "+";

        isPlus = false;

    }

   

   

    constant1 = int(constantinputtext);

    answer = int(answerinputtext);

    constantused1.text = constantinputtext;

    constantused2.text = constantinputtext;

    firststepbtn.removeEventListener(MouseEvent.CLICK, performfirststep);

    operatorinput.type = TextFieldType.DYNAMIC;

    constantinput.type = TextFieldType.DYNAMIC;

    answerinput.type = TextFieldType.DYNAMIC;

    secondstepbtn.addEventListener(MouseEvent.CLICK, performsecondstep);

}

function performsecondstep(e:MouseEvent):void {

    answeroutput.visible = true;

    if (isPlus ==true) {

        answeroutput.text = String(answer - constant1);

    } else {

        answeroutput.text = String(answer + constant1);

    }

   

}

Any help would be much appreciated.

Thank you,

Jeremy

TOPICS
ActionScript

Views

789

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
LEGEND ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

If you are not showing the code that ends up causing a problem, there is not much anyone can do to help.  Are you familiar with using the trace() function to track down problems with code?  Do you get any error messages when you find the program failing?

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

I posted the code that does not work at the bottom, the code that works is above it.  THere are no error messages, I just can't input any text into the input fields after I add the code to the performsecondstep 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
LEGEND ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

It wasn't clear which you were indicating has "dummy code".  I cannot see anything in the second set of code for that function that should cause any issue with matters that occur before trying to use that function. 

If you are finding that adding that code is the only thing you change that causes it to go from working to not working, then you should try adding one line of code to it at a time until you see it fails.  For a function that is not being called before the failure occurs, I would expect some kind of error to be generated for that function if it is the cause.

Just some minor details

- you can instantiate and assign in one line, and you do not need to instantiate in some cases where you do, just for example...

     var operatorinputtext:String;  // if it has no value to assign, there is no need to

     var isPlus:Boolean = true;     // no need for two lines

  

- you do not need to include the "== true" when you are testing a boolean value (or anything that can be differentiate as existing or not existing)

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

Still not sure what the problem is, it starts doing this when I add the if statement.  However, I figured out a workaround and it works fine.  It's not pretty code, but it works.  Thanks for the 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
LEGEND ,
Jun 22, 2012 Jun 22, 2012

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