3 Replies Latest reply on Jul 8, 2009 8:38 AM by rtalton

    setStyle not valid

    Benoitcn

       

       

       

       

      I try to change styles at runtime

       

       

       

       

      <mx:Button x="38" y="44" label="为中国喝彩" click="butClickHandler(event)"/>
       
      <mx:Canvas id="styleCanvas" id="styleCanvas" width="80" height="80">
                <mx:Label id="styleLabel" text="I'm Label"/> 
      
      </mx:Canvas>
       
       
      
      private function butClickHandler(event:MouseEvent):void  {
           /* it doesn't work */ 
           styleCanvas.setStyle("backgroundImage", "@Embed('bird.png')");
           /* but this works */      
           Button(event.target).setStyle("color", 0x0eeeee);
      }
      
      

       

        • 1. Re: setStyle not valid
          istrasci Level 1

          I believe both arguments to setStyle need to be Strings...  So in your case, it should be:

           

          private function butClickHandler(event:MouseEvent):void  {

               /* it doesn't work */
               styleCanvas.setStyle("backgroundImage", "@Embed('bird.png')");

               /* but this works -- I don't know how this would work*/     
               Button(event.target).setStyle("color", "0x0eeeee");
          }
          • 2. Re: setStyle not valid
            m.....

            If that doesn't work try

            @Embed(source='bird.png')
            
            
            
            • 3. Re: setStyle not valid
              rtalton Level 4

              You could accomplish this by first setting up bindable images, and then passing that into the setStyle method:

               

              [Bindable]
              private var imgBird:Class;
              [Embed(source="assets/images/bird.png")

               

              styleCanvas.setStyle("backgroundImage", imgBird);

               

              This allows you to re-use the image throughout your application without embedding it each time (you get a smaller file size).

              Yes, you must use quotes around the arguments, as stated earlier, but when embedding a Class, you don't.