2 Replies Latest reply on Apr 1, 2009 9:43 AM by Gregory Lafrance

    Buttons in Flex

      Hello all,

      I am trying to create a button with an image and text from an ActionScript class. NOT from the mxml file. It has to be created from an .as source.
      I cannot find any icon field in the public properties of the object.
      Can anyone tell me how to do this?

      Thanks, Francois
        • 1. Re: Buttons in Flex
          Peter Hahmann Level 1

          Icon is a style, so you have to use setStyle, like the example bellow.


          package br.com.sangari.rpformacao.utils
          import mx.controls.Button;

          public class btn extends Button
          private var myIcon:Class;

          public function btn()
          this.label = "My Button";
          this.setStyle("icon", myIcon);
          • 2. Re: Buttons in Flex
            Gregory Lafrance Level 6
            A more general answer to your question is that in Flex, there are true "properties" and there are "style properties".

            True properties and style properties are set in MXML with the propName="propValue" syntax, but in ActionScript, while true properties use this same syntax, style properties use the objName.setStyle("propName", "propValue") syntax, and to get the property, objName.getStyle("propName").

            However, in MXML, even Boolean and number values are enclosed in double-quotes, but in AS they are not.

            If you misspell a style property name in MXML you get an error, but if you misspell in AS your assignment or reference simply doesn't work, no error unless you try to use that value elsewhere and it is incorrect or not set.