0 Replies Latest reply on Oct 5, 2011 9:26 PM by gordon277

    Using SimpleButton in Flex - shrinks

    gordon277

      Hi,

       

      I've been successfully using SimpleButtons in Flex that are created in CS5 and exported as an .swc library. I basically use an SWFLoader, with a slight modification for enabling/disabling. The problem that I'm having is that when I click on a button and disable it at the same time, the button shrinks. Here is my class:

      <?xml version="1.0" encoding="utf-8"?>

          <mx:SWFLoader xmlns:fx="http://ns.adobe.com/mxml/2009"

                    xmlns:s="library://ns.adobe.com/flex/spark"

                    xmlns:mx="library://ns.adobe.com/flex/mx"

                    buttonMode="true">

       

          <fx:Script>

              <![CDATA[

       

                  override public function set enabled(value:Boolean):void

                  {

                      super.enabled = value;

                      invalidateProperties();

                  }

       

                  override protected function commitProperties():void

                  {

                      super.commitProperties();

       

                      if(source != null)

                      {

                          if(source.enabled != enabled)

                              invalidateSize();

       

                          source.enabled = enabled;

                          alpha = enabled ? 1 : .5;

                          SimpleButton(content).mouseEnabled = enabled;

                          buttonMode = enabled;

                      }

                  }

       

              ]]>

          </fx:Script>

       

      </mx:SWFLoader>

       

      Here is how I'm using it:

       

      <fx:Script>

              <![CDATA[

                  private function r():void

                  {

                      myButton.enabled = false;

                  }

              ]]>

          </fx:Script>

       

          <ui:FlashButton id="myButton" source="{new MySimpleButton()}" width="300" height="300" click="r()" />

       

      1) The problem only happens if I click on the button and disable it. If I add a second button, say "OtherButton" and it still calls r(), it will disable, but not shrink myButton

      2) I fixed this problem for ones where I don't explicitly set the width/height, by adding this code:

       

      if(source.enabled != enabled)

            invalidateSize();

      I know that invalidateSize() doesn't matter for components that have their width/height set.

       

      Using SimpleButtons like this overall works really well, except for this one problem. I've tried setting width/height/measuredWH/expliistWH inside commitProperties(), but couldn't solve the problem.

       

      Thanks a lot