Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

40 Your First inFormation-rich application · prettyPrint is public. It could have been protected or inter- nal. You cannot override private methods. · The overridden version prettyPrint maintains the same accessibility (public/protected/internal), the same number and type of parameters (none in this case), and the same return type ( String in this case). All the following examples are not implementable and will throw a compilation error of which the description is "Incompatible override." // changes accessibility, prettyPrint has to be public override internal function prettyPrint():String { ... } // changes signature, prettyPrint has no parameters override public function prettyPrint(p1:int):String{} // changes signature, prettyPrint returns a String override public function prettyPrint():Number {...} For sake of completeness we should mention that another important concept in object-oriented programming is the one of interfaces (not to be confused with user interfaces, or UI). Interfaces are a way to specify the behavior of a class (read its methods) with no need to provide a specific implementation. Such a concept is out of the scope of this book and will not be introduced further. If you want to know more about interfaces in ActionScript you can have a look at Yard et al.'s book, Object- Oriented ActionScript 3.0. Binding One of the most powerful tools in Flex is binding. In the intro- duction to this section we mentioned that the Flex framework embeds solutions to deal with common problems in UI devel- opment. How many times have you had to refresh the value of a component according to an interaction or the state of another component? Binding does exactly this: it allows us to bind an object to another one, so that whenever the first value (source) changes, the second (target) is updated accordingly. For example, we want to build a UI that allows the configu- ration of a button's label. To keep it simple, we will have a text input widget, which allows typing the new label, and a button. To improve the user experience of our application, we want the user to see changes in real time, as he or she types in the text input. In the terms introduced above, the text input is the source and the button label is the target. This is easily implementable in Flex by exploiting binding and the design view. In general, it is simpler to start by declaring the source. So we drag a text input component