8 Replies Latest reply on Apr 1, 2013 8:46 AM by Claudio González

    Problem with  uint

    fsoender Level 1

      I get an warning with this code, but I have the variable in binding already...

       

       

      Warning: Data binding will not be able to detect assignments to "NewBatteryStatus"

       

       

       

       

       

      [Bindable]

       

      public var NewBatteryStatus:String;

       

       

       

       

                switch(NewBatteryStatus)

                {

                case 1:                                                                                                                

                NewBatteryStatus = "Red";                                                                                         

                break;

       

                case 2:                                                                                                                

                NewBatteryStatus = "Green";

                break;

       

                default:                                                                                                                

                NewBatteryStatus = "Yellow";                                                                                                   

                break;                  

                }                                             

       

       

      <s:Button id="Battery" x="791" y="513" width="124" height="46" label="Battery" fontSize="20" color= "{new uint(NewBatteryStatus)}"/>

        • 1. Re: Problem with  uint
          pauland Level 4

          You cannot bind styles.

           

          Ask yourself  these questions:

           

          Is NewBatteryStatus a) a string, or b)a numerical type and why am I trying to use it as both?

           

          Why am I trying to set what is expected to be a string value to be a uint?

           

          Why do I continue to ignore the camel-case convention for variables, starting my variable names with a lower case letter and class names with a capital, thereby writing code that will tend to confuse from the very start.

           

          If binding was working, why is my variable name described as New, when really it's just the current battery status? the variable name should be something like batteryStatus or currentBatteryStatus but not newBatteryStatus.

          • 2. Re: Problem with  uint
            fsoender Level 1

            Ok, thanks for that info, I will use that, but why cant I write it like this:

             

             

            public var batteryStatus:String;

             

            BatteryStatus = "Red";

             

            <s:Button id="Battery" x="795" y="514" width="124" height="46" label="Battery" fontSize="20" color= "{(batteryStatus)}"/>

             

            but this work:

             

            <s:Button id="Battery" x="795" y="514" width="124" height="46" label="Battery" fontSize="20" color= "red"/>

             

             

            • 3. Re: Problem with  uint
              pauland Level 4

              Binding doesn't work with styles.  Maybe some else can say exactly why, but styles aren't quite the same as normal attributes and I don't think the bind mechanism can work with anything but straightforward attributes. Styles have to be set explicitly.

               

              Look styles up.

              • 4. Re: Problem with  uint
                fB3 Level 2

                Just change this...

                 

                "{(batteryStatus)}"

                 

                to this...

                 

                "{batteryStatus}"

                 

                and add [Bindable] to the var declaration.

                 

                 

                This should work.

                 

                [Bindable] public var batteryStatus:String;


                BatteryStatus = "Red";


                <s:Button id="Battery" x="795" y="514" width="124" height="46" label="Battery" fontSize="20" color= "{batteryStatus}"/>

                • 5. Re: Problem with  uint
                  fsoender Level 1

                  No, I have tried that before, won’t work either. get the same warning.

                   

                  Any other suggestions?

                  • 6. Re: Problem with  uint
                    pauland Level 4

                    You can't set it with binding. Set the style explicitly in code.

                     

                    battery.setStyle('color', 'red');

                    • 7. Re: Problem with  uint
                      fsoender Level 1

                      Thanks pauland, that worked

                      • 8. Re: Problem with  uint
                        Claudio González Most Valuable Participant

                        Please ignore this; it's just a test.