1 Reply Latest reply on Sep 7, 2010 9:34 PM by Shongrunden

    button state not working from actionscript

    raj_cap Level 1

      I am very new to flex . In flash builder 4 I am using following code to create a button with custom skin through action script. On button over state I am changing color to red and this is not working.

      However if I try to use mxml script to create button everything works fine including over state color change

       

      mxml code(working) - <s:Button skinClass="components.myButtonskin" x="164" y="29"/>

       

      action script code(not working) -

       

      private var myButton:myButtonskin;

      private function initApp():void{
        
        myButton = new myButtonskin();
        myButton.x = 14;
        myButton.y = 30;
        myGroup.addElement(myButton);

      }

       

      myButtonskin file -

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Skin xmlns:s="library://ns.adobe.com/flex/spark" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:flm="http://ns.adobe.com/flame/2008" xmlns:d="http://ns.adobe.com/fxg/2008/dt">
      <fx:Metadata>[HostComponent("spark.components.Button")]</fx:Metadata>
      <s:states>
        <s:State name="up"/>
        <s:State name="over"/>
        <s:State name="down"/>
        <s:State name="disabled"/>
      </s:states>
      <s:Group blendMode="multiply" flm:isolated="false" x="0" y="0"  >
        <s:Group d:id="22" flm:knockout="false" x="8" y="0">
         <s:Rect height="89" radiusX="8.4689" radiusY="8.4689" width="88" x="0" y="0">
          <s:fill>
           <s:SolidColor color="#ADC936" color.over="#FF0000"/>
          </s:fill>
         </s:Rect>
        </s:Group>
        <s:Path data="M 9.338 10.783 L 0 5.391 L 9.338 0 L 9.338 10.783 Z" winding="nonZero" x="0.329" y="38.091">
         <s:fill>
          <s:SolidColor color="#ADC936" color.over="#FF0000"/>
         </s:fill>
        </s:Path>
      </s:Group>
      </s:Skin>

        • 1. Re: button state not working from actionscript
          Shongrunden Adobe Employee

          I believe what you mean to do is instantiate a Button object and then assign its skin using setStyle():

           

          private var myButton:Button;

          private function initApp():void{
            
            myButton = new Button();
            myButton.x = 14;
            myButton.y = 30;

            myButton.setStyle("skinClass", components.myButtonSkin);
            myGroup.addElement(myButton);

          }