Macromedia flex 2 Manuale

Pagina di 254
130
Creating Simple Visual Components in ActionScript
                    case 73 :
                        if (currentFontSize < maxFontSize) {
                            currentFontSize = currentFontSize + 1;
                            setStyle('fontSize', currentFontSize);
                        } 
                        break;
                    // Was Ctrl-M pressed?  
                    case 77 :
                        if (currentFontSize > minFontSize) {
                            currentFontSize = currentFontSize - 1;
                            setStyle('fontSize', currentFontSize);
                        }
                        break;
                    default :
                        break;
                }           
            } 
        }
    }
}
In this example, the setter method checks that the specified font size is less than the 
predefined limit of 30 pixels. If the font size is greater than the limit, it sets it to the limit. 
Creating a default property
You can define a default property for your ActionScript components by using the 
[DefaultProperty]
 metadata tag. You can then use the default property in MXML as the 
child tag of the component tag without specifying the property name. For more information 
on using the default property, including an example, see “Setting the default property” in Flex 
2 Developer’s Guide
.