4 Replies Latest reply on Feb 5, 2007 5:38 AM by aspidistra

    If else statement actionscript errors

    aspidistra Level 1
      Hi
      I am trying to check the values that are entered add up to 100 (percent) - and that the field is not left blank either...I just don't know actionscript well enough to get it to work. All the given examples are not in depth enough to cover what I am trying to do. Can anyone point out what the actionscript should be ?

      //Calculates total price.
      two_btn.onPress = function() {
      priceTotal_txt.text = Number (field1) + Number (field2) + Number (field3) + Number (field4);
      if ((priceTotal_txt.text == null)||(priceTotal_txt.text <100)){
      gotoAndStop("retry");
      }else{
      _root.gotoAndStop (15);}
      --------------------------------------------------------
      **Error** Scene=Scene 1, layer=actionscript, frame=1:Line 30: Unexpected '||' encountered
      if (priceTotal_txt.text == null)||(priceTotal_txt.text <100)){

      **Error** Scene=Scene 1, layer=actionscript, frame=1:Line 32: Unexpected '}' encountered
      }else{

      Total ActionScript Errors: 2 Reported Errors: 2
      ---------------------------------------------------------------------------------------


      then on frame 5- frame label retry:

      //button function returns user to Frame 1
      tryAgain_btn.onPress = function() {
      gotoAndStop(1);
      };

      This causes an error :

      **Error** Scene=Scene 1, layer=Dialog boxes, frame=5:Line 2: Statement must appear within on/onClipEvent handler
      tryAgain_btn.onRelease = function(){

      Total ActionScript Errors: 1 Reported Errors: 1


      thanks
      E
        • 1. Re: If else statement actionscript errors
          Level 7
          aspidistra wrote:
          > Hi
          > I am trying to check the values that are entered add up to 100 (percent) - and
          > that the field is not left blank either...I just don't know actionscript well
          > enough to get it to work. All the given examples are not in depth enough to
          > cover what I am trying to do. Can anyone point out what the actionscript should
          > be ?
          >
          > //Calculates total price.
          > two_btn.onPress = function() {
          > priceTotal_txt.text = Number (field1) + Number (field2) + Number (field3) +
          > Number (field4);
          > if ((priceTotal_txt.text == null)||(priceTotal_txt.text <100)){
          > gotoAndStop("retry");
          > }else{
          > _root.gotoAndStop (15);}
          > --------------------------------------------------------
          > **Error** Scene=Scene 1, layer=actionscript, frame=1:Line 30: Unexpected '||'
          > encountered
          > if (priceTotal_txt.text == null)||(priceTotal_txt.text <100)){
          >
          > **Error** Scene=Scene 1, layer=actionscript, frame=1:Line 32: Unexpected '}'
          > encountered
          > }else{
          >
          > Total ActionScript Errors: 2 Reported Errors: 2


          I tried the code look ok, no warings or errors here. What version of
          Flash do you use?


          > --------------------------------------------------------------------------------
          > -------
          >
          >
          > then on frame 5- frame label retry:
          >
          > //button function returns user to Frame 1
          > tryAgain_btn.onPress = function() {
          > gotoAndStop(1);
          > };
          >
          > This causes an error :
          >
          > **Error** Scene=Scene 1, layer=Dialog boxes, frame=5:Line 2: Statement must
          > appear within on/onClipEvent handler
          > tryAgain_btn.onRelease = function(){
          >
          > Total ActionScript Errors: 1 Reported Errors: 1


          Is this script realy on the frame (can you see an [a] in the frame) or
          do you have a clip selected?
          • 2. Re: If else statement actionscript errors
            aspidistra Level 1
            Hi thanks

            The second script was on the button and on frame five which was causing the actionscript errors...now no actionscript errors with that out - BUTit still doesn't carry out the function (i.e. check the amounts are under 100 and fields not empty) - it just takes you to the 'retry' screen no matter what!! ...and also bizarrely then the button associated with the frame 5 (label retry) script below does not work at all!

            //button function returns user to Frame 1
            tryAgain_btn.onPress = function() {
            gotoAndStop(1); };

            E.
            • 3. Re: If else statement actionscript errors
              Level 7
              > if (priceTotal_txt.text == null)||(priceTotal_txt.text <100)){

              You have a missing '(' there after the 'if'. its not that hard to see
              --
              Jeckyl


              • 4. Re: If else statement actionscript errors
                aspidistra Level 1
                Hi
                Yes sorry in that particular snip of code I do as I have altered this code so often to try to get it to work...that is not the problem tho...even when that is added the logic of the conditional statement still does not work.

                Any ideas...instead of checking the logic i.e. does it add to 100 it just continues to frame 15 no matter what it adds to!

                Any ideas why????
                thanks
                E

                CODE :
                //Calculates total price, checking for empty field
                //and percentage not adding to 100.

                two_btn.onPress = function() {
                priceTotal_txt.text = Number (field1) + Number (field2) + Number (field3) + Number (field4);
                MyTotal = parseInt(priceTotal_txt.text)/60 * 31;
                MobTot = parseInt (mbcalls_txt.text);
                if ((priceTotal_txt.text == null)||(priceTotal_txt.text <100)){
                gotoAndStop("error");
                }else{
                _root.gotoAndStop (15);}
                };