1 Reply Latest reply on Mar 4, 2007 3:58 AM by JabbyPandaUA

    How  to chane background color

    kruse Level 1
      How do I change the background color of a vbox?

      I have tried this

      private function changeColour(colour : String) : void
      {
      mk.setStyle( "backgroundColor", colour );
      }

      <mx:VBox width="230"
      rollOver="changeColour('#f00dbad')"
      rollOut="changeColour('#0000')"
      id="mk">

      But it does not work properly. It is slow?
      The first time I navigate ower the vbox nothing happens.
      I can navigate ower the vbox several times before anything happens.

      I there a nother way to change background color of a vbox when navigating ower the vbox?

      /Morten
        • 1. Re: How  to chane background color
          JabbyPandaUA Level 3
          Your example works for me, but in case if you experience some troubles with rolling over VBox and colours not changing, try to assign event handlers to VBox instance in "creationComplete" event handler:

          Example follows:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          layout="horizontal" width="100%" height="100%" creationComplete="onCreationComplete()"
          >
          <mx:Script>
          <![CDATA[
          private function onCreationComplete() : void {
          mk.addEventListener(MouseEvent.ROLL_OVER, changeColourTo);
          mk.addEventListener(MouseEvent.ROLL_OUT, changeColourFrom);
          }
          private function changeColourTo(evt : MouseEvent) : void
          {
          mk.setStyle( "backgroundColor", 0xFF0000);
          }

          private function changeColourFrom(evt : MouseEvent) : void
          {
          mk.setStyle( "backgroundColor", 0x000000);
          }
          ]]>
          </mx:Script>
          <mx:VBox id="mk" height="200">
          <mx:Button label="Expand" />
          <mx:Button label="Shrink"/>
          </mx:VBox>
          </mx:Application>