0 Replies Latest reply on Jun 2, 2017 2:16 AM by Ibarim

    change skin on all instances of mx.Button with static var

    Ibarim Level 1

      Hi,

      I created class extending Button in mxml and this class has skin set to some flash picture from .swc.

      I would like to give users option to change look of the button. To do that I need to change skin of all instances of this button. I figured out that I'll create static function to change skin style. But of course it doesn't work

      In creationComplete event handler I attach the 'this' property to static var 'thisstatic'. Then when user changes option static functions are called inside my button class: test() and test2(). These functions should change skin by calling the 'thisstatic' var.  I tried setStyle, StyleManager and CSS styles, and nothing happens.

      I'm not sure if I made something wrong with the static/dynamic connection or changing skin dynamically is even possible, coz as far as I read forums it might not be possible at all.

       

       

      Example of my button class: (ButtonSkin is default mx button skin and btn_skin is my skin from .swc picture)

       

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

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

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

        skin="{btn_skin}" creationComplete="cc()">

      <fx:Script>

        <![CDATA[

       

      private function cc():void {

            thisstatic = this;

      }

       

      private static var thisstatic:Button;

      public static function test():void {

             trace('Btn.test()');

      //each solution from below doesn't work

             //thisstatic.setStyle('skin',ButtonSkin);

             //fl.managers.StyleManager.setStyle('skin',ButtonSkin);

             //fl.managers.StyleManager.setComponentStyle(thisstatic,'skin',ButtonSkin);

             //thisstatic.styleName = 'noskinstyle';

        }

       

        public static function test2():void {

             trace('Btn.test2()');

      //each solution from below doesn't work

             //thisstatic.setStyle('skin',btn_skin);

             //fl.managers.StyleManager.setStyle('skin',btn_skin);

             //fl.managers.StyleManager.setComponentStyle(thisstatic,'skin',btn_skin);

             //thisstatic.styleName = 'skinstyle';

        }

      ]]>

        </fx:Script>

      <fx:Style>

        @namespace s "library://ns.adobe.com/flex/spark";

        @namespace mx "library://ns.adobe.com/flex/mx";

       

        .noskinstyle {

        skin: null;

        }

       

        .skinstyle {

        skin: btn_skin;

        }

        </fx:Style>

      </mx:Button>