5 Replies Latest reply on Jul 23, 2009 6:59 PM by PeakDigital

    setStyle has no effect on borderColor?

    PeakDigital Level 1

      I use the following function as a customized validation formatter. If a control fails validation, the function turns its background and border orange. For the invalid condition, the formatting works exactly as I expect.

       

      If it validates, it is supposed to return the properties to their original settings. However, the borderColor fails to change.. The other properties are reset properly.

       

      Any ideas why this one property would fail to be set?

       

      public function formatControlErrorStatus(theControl:Object,isError:Number):void
          {//valid/invalid trigger must pass name of target control and 0 for no error, 1 for error
          if(isError==1)
              {
              theControl.setStyle("borderColor","#FF4B00");
              theControl.setStyle("borderThickness",2);
              theControl.setStyle("backgroundColor","#FF4B00");
              theControl.setStyle("backgroundAlpha",.4);
              }
          else if (isError==0)
              {
              theControl.setStyle("borderColor","#7D6441");
              theControl.setStyle("borderThickness",1);
              theControl.setStyle("backgroundColor","#FFFFFF");
              theControl.setStyle("backgroundAlpha",.75);
              }
          }
      
      

       

      Thanks.

      Paul

       

      UPDATE: I just discovered that if I call the validator twice when there is a valid value in the control, the second time the border color changes as expected?!

        • 1. Re: setStyle has no effect on borderColor?
          Gregory Lafrance Level 6

          This may not be relevant in this case, but I just wanted to make sure you are not treating 1 as true and 0 as false, as that might not work.

          • 2. Re: setStyle has no effect on borderColor?
            tanyagray01

            Not sure if it would work, but you could try putting the styles in an external stylesheet and importing that stylesheet into your Flex project:

             

            .errorStyle{     borderColor: #FF4B00;
                 borderThickness: 2;
                 backgroundColor: #FF4B00;
                 backgroundAlpha: 0.4;
            }
            
            .normalStyle{
                 borderColor: #7D6441;
                 borderThickness: 1;
                 backgroundColor: #FF4B00;
                 backgroundAlpha: 0.75;
            }
            

             

            and then have the actionscript:

             

            public function formatControlErrorStatus(theControl:Object,isError:Number):void
                {// valid/invalid trigger must pass name of target control and 0 for no error, 1 for error
                if(isError == 1)
                    {
                    theControl.styleName = "errorStyle";
                    }
                else if(isError == 0)
                    {
                    theControl.styleName = "normalStyle";
                    }
                }

             

            Even if separating out the code like this doesn't fix your problem, at least it might make it easier to figure out what's going wrong.

             

            Also, Greg has a point, you should probably be using a Boolean rather than a number when you're checking if the error case is true or false.

            • 3. Re: setStyle has no effect on borderColor?
              PeakDigital Level 1

              Thank you both for replying. I will go back in and change that to a Boolean,  I'm still learning all the details on Flex.

               

              I added the styling to my app's main CSS file, but it had the same effect as if I called each style property in the function (my original code).

               

              Interestingly, I can change the border to "none" and it disappears, but nothing I have tried for the color changes it.

              • 4. Re: setStyle has no effect on borderColor?
                tanyagray01 Level 1
                public function formatControlErrorStatus(theControl:Object,isError:Number):void
                    {// valid/invalid trigger must pass name of target control and 0 for no error, 1 for error
                    if(isError == 1)
                        {
                        theControl.styleName = "errorStyle";
                        }
                    else if(isError == 0)
                        {
                        theControl.styleName = "normalStyle";
                        }
                     theControl.validateNow(); //added this line only
                    }

                 

                Just out of interest, try that. I'm definitely no Flex expert and that may be completely incorrect and bad code... but at least see if it works.

                 

                validateNow() - Validate and update the properties and layout of this object       and redraw it, if necessary. - According to the Adobe documentation.

                • 5. Re: setStyle has no effect on borderColor?
                  PeakDigital Level 1

                  My apologies for the delayed response.


                  Thank you for the suggestion. Unfortunately, validateNow is one of the things I already tried. No effect.