4 Replies Latest reply on Sep 23, 2010 12:20 PM by bignuttjob

    New to Flex and Actionscript

    bignuttjob

      Hi,

       

      Firstly, apologies for the newbie question, but I can't find the answer on-line or in my Flex book.

       

      I want to change the background colour of a TextInput field when the value changes. So I have a CHANGE event set-up and when it triggers I can check the value, but I don't understand why I can't set the contentBackgroundColor in Actionscript as I do in Flex. Here's the code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="620">

      <fx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.events.FlexEvent;
      import spark.events.TextOperationEvent;

      protected function text1_changeHandler(event:TextOperationEvent):void
      {
      if(event.target.text==10)
      text1.contentBackgroundColor="#FFE4C4"; // How should I do this?
      }

       

      ]]>
      </fx:Script>

       

      <s:Panel y="10" width="800" height="600" title="Title1" horizontalCenter="-68">

      <s:TextInput id="text1" x="569" y="123" text="100" width="157" height="25" contentBackgroundColor="#FFFFFF" change="text1_changeHandler(event)"/>

      </s:Panel>
      </s:Application>

       

      Thanks!
      TimN

        • 1. Re: New to Flex and Actionscript
          Devtron Level 3

          Maybe you cannot do this because it is a spark control?

           

          I am in the same boat with using "themes". Dont ever use a pre-defined theme from Adobe. You wont be able to change anything very easily

          • 2. Re: New to Flex and Actionscript
            Subeesh Arakkan Level 4

            text1.setStyle("contentBackgroundColor","#FFE4C4");

            • 3. Re: New to Flex and Actionscript
              Anitha Selvaraj Level 2

              You can also do like this.

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="620">
                  <fx:Style>
                      @namespace s "library://ns.adobe.com/flex/spark";
                      @namespace mx "library://ns.adobe.com/flex/mx";
                      .textInput{
                          content-background-color:"#FFE4C4";
                      }
                  </fx:Style>
                  <fx:Script>
                      <![CDATA[
                          import mx.controls.Alert;
                          import mx.events.FlexEvent;
                          import spark.events.TextOperationEvent;
                         
                          protected function text1_changeHandler(event:TextOperationEvent):void
                          {
                              if(event.target.text==10)
                                  text1.styleName="textInput";
                          }
                      ]]>
                  </fx:Script>
                 
                  <s:Panel y="10" width="800" height="600" title="Title1" horizontalCenter="-68">
                     
                      <s:TextInput id="text1" x="569" y="123" text="100" width="157" height="25" contentBackgroundColor="#FFFFFF" change="text1_changeHandler(event)"/>
                     
                  </s:Panel>
              </s:Application>

               

              Regards,

              Anitha

              • 4. Re: New to Flex and Actionscript
                bignuttjob Level 1

                Thanks guys!

                Learning fast now.

                 

                TimN