5 Replies Latest reply: Mar 4, 2013 8:02 AM by fsoender RSS

    Help With Code

    fsoender

      Why cant I write the code like this in FelxBuilder?

       

       

      public var ValueIn:Sring

       

       

      if(ValueIn == 1) {

      NewBatteryStatus = "Red";

      } else if(ValueIn == 2) {

      NewBatteryStatus = "Green";

      }

        • 1. Re: Help With Code
          l33tian Community Member

          because it represents all things wrong as far as actionscript is concerned.

          1. Wrong Type (You meant "String" instead of sring),

          2, the default value for string is null(i think), you are comparing against integers

          • 2. Re: Help With Code
            fsoender Community Member

            Yes its a Sting, I miss typed it.

            Do you have any sugestions how to fix it?

             

            Code?

            • 3. Re: Help With Code
              l33tian Community Member

              String not sting or sring,

               

              you need to pick a book on actionscript. thats how you can fix it.

              • 4. Re: Help With Code
                DeanLoganBH Community Member

                As they pointed out, you probably should read up on ActionScript to figure this out, but....

                 

                Things that are missing.

                public var ValueIn:String = "";
                
                

                Things that are wrong .

                if(ValueIn == 1) 
                

                However, the entire way your handing this is incorrect, because you can't treat a String as a Number to determine if the value equals something.  It looks like you are trying to pass in a numeric value to a function in or to set a global variable to a string value.  This is how I would do it.  But, you should figure out why.

                 

                 

                <declarations>
                     <s:String id="NewBatteryStatus" />
                </declarations>
                 
                <fx:Script>
                      <![CDATA[
                           
                           private function batteryStatusCheck(batteryValue:int):void {
                                switch(batteryValue):
                                     case 1:
                                         NewBatteryStatus = "Red"; 
                                         break;
                                    case 2:
                                         NewBatteryStatus = "Green"; 
                                         break;
                                    default:
                                         NewBatteryStatus = "Black"; 
                                         break;                    
                           }
                       ]]>
                 </fx:Script>
                
                • 5. Re: Help With Code
                  fsoender Community Member

                  Thanks guys, got a book