1) What’s the difference between Java and AS3 getters and setters?(*)
In Java, getter and setter methods have to be explicitly called.
While in AS3, they’re called automatically and externally
indistinguishable from public properties.
While in AS3, they’re called automatically and externally
indistinguishable from public properties.
For instance trace(myClass.foo) might be referencing a public property
or it might be referencing the method “public get foo():Object”. It
makes no difference to an external class.
—
You can expand on this a bit more to describe why this is useful. The
implications are that, unlike in Java, all variables in a class are
generally public. Java standard practices are to create only public
getters and setters while keeping the variables private. The reason
for only allowing methods to be publicly accessible is so that 1) they
can be overridden and 2) their implementation can change without
altering class interface.
or it might be referencing the method “public get foo():Object”. It
makes no difference to an external class.
—
You can expand on this a bit more to describe why this is useful. The
implications are that, unlike in Java, all variables in a class are
generally public. Java standard practices are to create only public
getters and setters while keeping the variables private. The reason
for only allowing methods to be publicly accessible is so that 1) they
can be overridden and 2) their implementation can change without
altering class interface.
AS3 addresses both of these concerns because, as described above, a
public property can be replaced with a getter and setter without
changing the interface. And an inherited public property can actually
be overridden by a subclass.
public property can be replaced with a getter and setter without
changing the interface. And an inherited public property can actually
be overridden by a subclass.
For example, this is valid:
public class A
{
public var foo:Object;
}
public class A
{
public var foo:Object;
}
public class B extends A
{
override public function get foo():Object{return ‘bar’};
override public function set foo(value:Object):void{};
}
2) Explain how binding works in mxml components.{
override public function get foo():Object{return ‘bar’};
override public function set foo(value:Object):void{};
}
Data binding is the process of tying the data in one object to another object. It provides a convenient way to pass data around in an application. Adobe Flex 2 provides three ways to specify data binding:the curly braces ({}) syntax and the <mx:Binding> tag in MXML and the BindingUtils methods in ActionScript.
Data binding requires a source property, a destination property, and atriggering event that indicates when to copy the data from the source to the destination. To use a property as the source of a data binding expression, the component must be implemented to support data binding, which means that the component dispatches an event when the value of the property changes to trigger the binding.
At compile time, the MXML compiler generates code to createActionScript Watcher and Binding objects that correspond to the binding tags and expressions found in an MXML document. At run time, Watcher objects are triggered by change events that come from the constituent parts of binding source expressions; the Watcher objects then trigger Binding objects to execute bindings.
When you specify a property as the source of a data binding, Flex monitors not only that property for changes, but also the chain of properties leading up to it. The entire chain of properties, including the destination property, is called a “bindable property chain“. In the following example, firstName.text is a bindable property chain that includes both a firstName object and its text property:
<first>{firstName.text}</first>
Its not necessary that the binding executes automatically. In the following case the binding wont execute automatically as expected.
1. Binding does not execute automatically when you change an entire item of a dataProvider property.
2. Binding also does not execute automatically for subproperties of properties that have [Bindable] metadata.
3. Binding also does not execute automatically when you are binding data to a property that Flash Player updates automatically, such as the mouseX property.
The executeBindings() method of the UIComponent class executes all the bindings for which a UIComponent object is the destination. All containers and controls, as well as the Repeater component, extend the UIComponent class. The executeChildBindings() method of the Container and Repeater classes executes all of the bindings for which the child UIComponent components of a Container or Repeater class are destinations. All containers extend the Container class. However, you should only use the executeBindings() method when you are sure that bindings do not execute automatically.
3) What’s the difference between ChangeWatcher.watch, and BindingUtils.bindProperty?
Acts like the watch on AS2. It watches a variable for changes and when something happens fires an
event. Make sure you call the canWatch to ensure that you can watch it!
There are 3 ways to specify the second parameter, the chain.
1. A String containing the name of a public bindable property of the host object.
ChangeWatcher.watch(this, "myvar", handler)
2. An Object in the form: { name: property name, access: function(host) { return host[name] } }.
The Object contains the name of a public bindable property, and a function which serves as a getter
for that property.
ChangeWatcher.watch(this, { name:"myvar", getter: function():String { return "something" }},
handler);
3. A non-empty Array containing any combination of the first two options. This represents a chain
of bindable properties accessible from the host. For example, to watch the property host.a.b.c, call
the method as: watch(host, ["a","b","c"]
BindingUtils.bindProperty
Works pretty much the same way as the watch, but instead of having to handle and event it allows
you to immediately bind two properties one-way.
The first two parameters are for the the target, the second parameters are the triggers.
BindingUtils.bindProperty( this, "va1", this, "var2");
Note : Make sure you add the flex framework.swc to your project Library Path to have access to the
mx.binding.util class.
4) Why would you want to keep a reference to a ChangeWatcher and call unwatch()?
The ChangeWatcher class defines utility methods that you can use with bindable Flex properties. These methods let you define an event handler that is executed whenever a bindable property is updated.
unwatch () method:
Detaches this ChangeWatcher instance, and its handler function, from the current host. You can use the reset() method to reattach the ChangeWatcher instance, or watch the same property or chain on a different host object.
public function unwatch():void
You can instruct any container or control to listen for events dispatched by another container or control. When Flash Player dispatches an Event object, that Event object makes a roundtrip journey from the root of the display list to the target node, checking each node for registered listeners. The target node is the node in the display list where the event occurred. For example, if a user clicks a Button control named Child1, Flash Player dispatches an Event object with Child1 defined as the target node.
The event flow is conceptually divided into three parts: the capturing phase, the targeting phase, and the bubbling phase, as briefly described next.
About the capturing phase
The first part of the event flow is called the capturing phase. This phase comprises all of the nodes from the root node to the parent of the target node. During this phase, Flash Player examines each node, starting with the root, to see if it has a listener registered to handle the event. If it does, Flash Player sets the appropriate values of the Event object and then calls that listener. Flash Player stops after it reaches the target node's parent and calls any listeners registered on the parent.
About the targeting phase
The second part of the event flow, the targeting phase, consists solely of the target node. Flash Player sets the appropriate values on the Event object, checks the target node for registered event listeners, and then calls those listeners.
About the bubbling phase
The third part of the event flow, the bubbling phase, comprises all of the nodes from the target node's parent to the root node. Starting with the target node's parent, Flash Player sets the appropriate values on the Event object and then calls event listeners on each of these nodes. Flash Player stops after calling any listeners on the root node.
The mechanism through which event objects are passed from the objects that generates an event up through the containership hierarchy
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
dispatchEvent(event:Event):Boolean
hasEventListener(type:String):Boolean
willTrigger(type:String):Boolean
8) What does calling preventDefault() on an event do? How is this enforced?
You can use the Event.cancelable property to check whether you can prevent the default behavior associated with a particular event. If the value of Event.cancelable is true, then preventDefault() can be used to cancel the event; otherwise, preventDefault() has no effect.
These are some of the differences :
· Native support for Adobe AIR – Flex 3 introduces new components and incorporates the Adobe AIR development tools into the SDK and Flex Builder.
· Persistent framework caching – You can make Flex 3 applications as small as 50K when leveraging the new Flash Player cache for Adobe platform components. In fact the size of the resulting swf size had reduced for a larger bit.
· Flex Builder productivity enhancements – Flex Builder 3 introduces refactoring support, new profilers for performance and memory tuning, and code generation tools for data access.
· Integration with Creative Suite 3 – The Flex Component Kit for Flash CS3 allows Flash CS3 users to build components that can be seamlessly integrated into a Flex application, while Flex Builder 3 adds new wizards for importing assets from CS3 applications as skins.
· Advanced DataGrid – The Advanced DataGrid is a new component that adds commonly requested features to the DataGrid such as support for hierarchical data, and basic pivot table functionality.
· First steps toward open source Flex. As a first step toward making Flex an open source project, Adobe have opened up the Flex and Flex Builder bug tracking system to the public, as well as published detailed roadmap information.
10) What are some ways to specify styles on components?
11) What is the problem with calling setStyle()?
You should try to apply style sheets rather than use the setStyle() method because it is computationally expensive. This method should only be used when you are changing an object's styles during run time.
You cannot get or set style properties directly on a component as you can with other properties. Instead, you set style properties at run time by using the getStyle() and setStyle() ActionScript methods.
12) How do you use css styles in flex?
13) Explain the difference between creating an effect and setting the target as opposed to adding an effectListener ?
For example, the following code creates two zoom effects: one for shrinking the component slightly, and one for reverting it to its original size. These effects are assigned, by using their unique IDs, to the mouseDownEffect and mouseUpEffect triggers on the Button component.
<mx:Application ...>
<mx:Zoom id="shrink" duration="100" zoomHeightTo=".9" zoomWidthTo=".9" />
<mx:Zoom id="revert" duration="50" zoomHeightTo="1" zoomWidthTo="1" />
<mx:Panel title="Bouncy Button" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10" autoLayout="false" left="41" top="24" right="42">
<mx:Button id="bouncyButton" label="Click me!"
mouseDownEffect="{shrink}" mouseUpEffect="{revert}"/>
</mx:Panel>
</mx:Application>
14) How do you identify a component created in a repeater?
A Repeater component executes initially when it is instantiated. If the Repeater component's dataProvider property exists, it proceeds to instantiate its children, and they instantiate their children, recursively.
The Repeater component re-executes whenever its dataProvider, startingIndex, or count properties are set or modified either explicitly in ActionScript, or implicitly by data binding.
When a Repeater component re-executes, it destroys any children that it previously created (assuming the recycleChildren property is set to false), and then reinstantiates its children based on the current dataProvider property.
Preinitialize: The application has been instantiated but has not yet created any child components. Initialize: The application has created child components but has not yet laid out those components. creationComplete: The application has been completely instantiated and has laid out all components
18) What is AMF?
AMF is a binary format based loosely on the Simple Object Access Protocol (SOAP). It is used primarily to exchange data between an Adobe Flash application and a database, using a Remote Procedure Call. Each AMF message contains a body which holds the error or response, which will be expressed as an ActionScript Object. AMF was introduced with Flash Player 6, and this version is referred to as AMF 0. It was unchanged until the release of Flash Player 9 and ActionScript 3.0, when new data types and language features prompted an update, called AMF 3.
19) What are the Advantages and Disadvantages of flex
Flex advantages: very capable IDE, Images are part of a flash movie and can’t be downloaded directly, supported by Adobe, XML based language, ability to leverage flash components into the application, great speed increase over previous versions of flash (if that was even possible).
Flex disadvantages: Needs the flash player, Need to learn and XML based language and possibly actionscript to build real applications
20) What are the config files that are used to connect Java and Flex applications?
messaging-config.xml,
proxy-config.xml,
No comments:
Post a Comment