AS3 Error, help needed!

  • Rika
  • Newbie
  • Newbie
  • Rika
  • Posts: 14
  • Loc: Singapore

Post 3+ Months Ago

This is my AS3 coding, however this error for line else{standarweight...txtinches.text));keeps showing up 1067: Implicit coercion of a value of type String to an unrelated type Number. Can anyone help me?


ACTIONSCRIPT Code: [ Select ]
stop();
btn_standard.addEventListener(MouseEvent.CLICK, standard);
function standard(evt:MouseEvent):void {
   gotoAndStop(1);
}
btn_metric.addEventListener(MouseEvent.CLICK, metric);
function metric(evt:MouseEvent):void {
   gotoAndStop(2);
}
 
var standardweight:Number=0;
 
//restrict to numbers and fullstops
txtpounds.restrict = "0-9, . ";
txtinches.restrict = "0-9, . ";
txtkg.restrict = "0-9, . ";
txtmetre.restrict = "0-9, . ";
 
submit_standard.addEventListener(MouseEvent.CLICK, stopUser);
 
function stopUser(evt:MouseEvent):void {
   if (txtpounds.text == "") {
      stage.focus = txtpounds;
   }
   else if (txtinches.text == "") {
      stage.focus = txtinches;
   }
   else {
      standardweight = Number(txtpounds.text)/((txtinches.text)*(txtinches.text));
         if (standardweight <= 18.5) {
            gotoAndStop(3);
         }
         else if(18.5 >= standardweight <= 24.9) {
            gotoAndStop(4);
         }
         else if(25 >= standardweight <= 29.9) {
            gotoAndStop(5);
         }
         else if(30 >= standardweight <= 34.9) {
            gotoAndStop(6);
         }
         else if(35 >= standardweight <= 39.9) {
            gotoAndStop(7);
         }
         else if(standardweight >= 40) {
            gotoAndStop(7);
         }
         else {
            gotoAndStop(1);
         }
   }
}
  1. stop();
  2. btn_standard.addEventListener(MouseEvent.CLICK, standard);
  3. function standard(evt:MouseEvent):void {
  4.    gotoAndStop(1);
  5. }
  6. btn_metric.addEventListener(MouseEvent.CLICK, metric);
  7. function metric(evt:MouseEvent):void {
  8.    gotoAndStop(2);
  9. }
  10.  
  11. var standardweight:Number=0;
  12.  
  13. //restrict to numbers and fullstops
  14. txtpounds.restrict = "0-9, . ";
  15. txtinches.restrict = "0-9, . ";
  16. txtkg.restrict = "0-9, . ";
  17. txtmetre.restrict = "0-9, . ";
  18.  
  19. submit_standard.addEventListener(MouseEvent.CLICK, stopUser);
  20.  
  21. function stopUser(evt:MouseEvent):void {
  22.    if (txtpounds.text == "") {
  23.       stage.focus = txtpounds;
  24.    }
  25.    else if (txtinches.text == "") {
  26.       stage.focus = txtinches;
  27.    }
  28.    else {
  29.       standardweight = Number(txtpounds.text)/((txtinches.text)*(txtinches.text));
  30.          if (standardweight <= 18.5) {
  31.             gotoAndStop(3);
  32.          }
  33.          else if(18.5 >= standardweight <= 24.9) {
  34.             gotoAndStop(4);
  35.          }
  36.          else if(25 >= standardweight <= 29.9) {
  37.             gotoAndStop(5);
  38.          }
  39.          else if(30 >= standardweight <= 34.9) {
  40.             gotoAndStop(6);
  41.          }
  42.          else if(35 >= standardweight <= 39.9) {
  43.             gotoAndStop(7);
  44.          }
  45.          else if(standardweight >= 40) {
  46.             gotoAndStop(7);
  47.          }
  48.          else {
  49.             gotoAndStop(1);
  50.          }
  51.    }
  52. }
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Read this and see if it makes sense to you
http://www.wuup.co.uk/as3-quick-tips-st ... ice-versa/

I'm not very good with converting strings to numbers and back again, etc, but I can tell you that's why you're getting that error. It's a data type mismatch and you're trying to perform a calculation on it that isn't working.

Unfortunately I can't tell you how exactly to write it correctly at this point. I suck at math. Even in Flash lol.
  • Rika
  • Newbie
  • Newbie
  • Rika
  • Posts: 14
  • Loc: Singapore

Post 3+ Months Ago

Thanks the link fixed the problem!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.