flex questions

22
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. 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. 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. For example, this is valid: 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. or Explain 3 different ways to achieve data binding

Upload: gayathri-haldankar

Post on 06-Nov-2015

213 views

Category:

Documents


0 download

DESCRIPTION

test

TRANSCRIPT

1) Whats the difference between Java and AS3 getters and setters?(*)

In Java, getter and setter methods have to be explicitly called.

While in AS3, theyre 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.

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.

For example, this is valid:

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.

or

Explain 3 different ways to achieve data binding

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 tag in MXML and the BindingUtils methods in ActionScript.

Data binding requires a source property, a destination property, and a triggering 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 create ActionScript 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:

{firstName.text}

Its not necessary that the binding executes automatically. In the following case the binding wont execute automatically as expected.

Binding does not execute automatically when you change an entire item of a dataProvider property.

Binding also does not execute automatically for subproperties of properties that have [Bindable] metadata.

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) Whats the difference between ChangeWatcher.watch, and BindingUtils.bindProperty?

Changewatcher.watch is used to watch the changes to a property and when that happens execute some function. BindingUtils.bind is used to bind a property of an object to another property of another object. In-fact the ChangeWatcher.watch() uses BindingUtils.bind to do the trick.

Eg : ChangeWatcher.watch(myObject, myProperty, myPropertyChanged);

Here, whenever the myProperty of the object myObject is changed, the function (handler) myPropertyChanged is executed.

BindingUtils.bindProperty(textBox, text, myObject, myProperty);

Usually this is given in the creationComplete event. Here in this example, whenever myProperty of the object myObject is changed, the text property of the text box textBox is changed.

ChangeWatcher.watch returns a ChangeWatcher object, which can be saved to unwatch at later point of time.

4) Why would you want to keep a reference to a ChangeWatcher and call unwatch()?

The watch function returns an instance of ChangeWatcher which we can then use to do other things. The most important of this is to stop the ChangeWatcher. To stop watching we use a function named unwatch.

var cw:ChangeWatcher = ChangeWatcher.watch(myObject, myProperty,myPropertyChanged);

//when you want to stop watching

cw.unwatch();5)How does Flex event system works?

Events let a developer know when something happens within a Flex application. They can be generated by user devices, such as the mouse and keyboard, or other external input, such as the return of a web service call. Events are also triggered when changes happen in the appearance or life cycle of a component, such as the creation or destruction of a component or when the component is resized. We can handle these events in our code by adding an event handler. Event handlers are the functions or methods that we write to respond to specific events. They are also sometimes referred to as event listeners.

The event model in Flex comprises the Event object and its subclasses, and the event dispatching model. We 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

During each of these phases, the nodes have a chance to react to the event. For example, assume the user clicks a Button control that is inside a VBox container. During the capturing phase, Flex checks the Application object and the VBox for listeners to handle the event. Flex then triggers the Buttons listeners in the target phase. In the bubbling phase, the VBox and then the Application are again given a chance to handle the event but now in the reverse order from the order in which they were checked in the capturing phase.

During any phase, we can stop the traversal of the display list by calling one of the following methods on the Event object:

stopPropagation()

stopImmediatePropagation()

We can call either the eventsstopPropagation()method or thestopImmediatePropagation()method to prevent an Event object from continuing on its way through the event flow. The two methods are nearly identical and differ only in whether the current nodes remaining event listeners are allowed to execute. ThestopPropagation()method prevents the Event object from moving on to the next node, but only after any other event listeners on the current node are allowed to execute.

ThestopImmediatePropagation()method also prevents the Event objects from moving on to the next node, but it does not allow any other event listeners on the current node to execute.

6) What is event Bubbling?

The mechanism through which event objects are passed from the objects that generates an event up through the containership hierarchy. Event bubbling means an event dispatched from a display object will bubble up the display list, starting from the object dispatching the event to the stage. An event only bubbles if itsbubblesproperty is set totrue. Mouse events and keyboard events are among those that bubble; it is less common for higher-level events that are dispatched by Flex to bubble. Events that can be bubbled includechange,click,doubleClick,keyDown,keyUp,mouseDown, andmouseUp. During the bubbling phase, Flex changes the value of thecurrentTargetproperty on the Event object to match the current node whose listener is being called. Thetargetproperty continues to refer to the dispatcher of the event.

7) How do you add event listeners in mxml components and AS3 components?

In AS3, we can do it like this :

addEventListener(enableChanged, enableChangedListener);

dispatchEvent(new Event(enableChanged));

In MXML it is more simple :

8) What does calling preventDefault() on an event do? How is this enforced?

Cancels an events default behavior if that behavior can be canceled.. For example, the doubleClick event has an associated default behavior that highlights the word under the mouse pointer at the time of the event. Your event listener can cancel this behavior by calling the preventDefault() method. 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.

9)What are the differences between Flex 2.0 and Flex 3.0?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?

declaring styles through CSS for each component

declaring style classes in CSS and giving the class name in styleName property of component

tag in MXML

using setStyle() method for AS3

11) What is the problem with calling setStyle()

When we are instantiating an object and setting the styles for the first time, we should try to apply style sheets rather than use the setStyle() method because it is computationally expensive. This method should only be used when we are changing an objects styles during run time.

12) How do you use css styles in flex?

13) Explain different ways of using style sheets in Flex application.

14) Explain the difference between creating an effect and setting the target as opposed to adding an effectListener

15) What do repeater components do?

16. How do you use a repeater?

17) How do you identify a component created in a repeater?

18) Explain the component lifecycle.

or

Explain the UI component life cycle including important methods like initialize() and createChildren()

or

What are the methods called when a UI component is intialized?

Preinitialize: The application has been instantiated but has not yet created any child components.

CreateChildren:Flex calls the createChildren() method in response to the call to the addChild() method to add the component to its parent.

invalidateProperties(): marks a component so that its commitProperties() method gets called during a later screen update.

invalidateSize (): Marks a component so that its measure() method gets called during a later screen update.

invalidateDisplayList (): Marks a component so that its updateDisplayList() method gets called during a later screen update.

Initialize: The application has created child components but has not yet laid out those components.

CommitProperties:Flex calls the commitProperties() method when you use the addChild() method to add a component to a container, or when you call the invalidateProperties() method of the component. Calls to the commitProperties() method occur before calls to the measure() method. This lets you set property values that might be used by the measure() method.

Calls the components measure() method.

Measure : calculates the default size, and optionally the default minimum size, of the component. This is an advanced method that you might override when creating a subclass of UIComponent.

The default implementation of measure() sets measuredWidth, measuredHeight, measuredMinWidth, and measuredMinHeight to 0.

LayoutChrome:Calls the components (Adobe help mention this method is in UIComponent where as it is in container class) containers layoutChrome() method.

The Container class, and some subclasses of the Container class, use the layoutChrome() method to define the border area around the container.

Calls the components updateDisplayList() method.

UpdateDisplayList(): method sizes and positions the children of your component based on all previous property and style settings, and draws any skins or graphic elements that the component uses. The parent container for the component determines the size of the component itself.

UpdateComplete :Dispatched when an object has had its commitProperties(), measure(), and updateDisplayList() methods called (if needed). This is the last opportunity to alter the component before it is displayed. All properties have been committed and the component has been measured and layed out.

creationComplete: The application has been completely instantiated and has laid out all components

For an ultimate guid see here : http://flexcomps.wordpress.com/2008/05/09/flex-component-life-cycle

19) How invalidate / commitProperties work specifically

20) Questions about dataServices

21) A general understanding of MVC

or

How do you implement MVC in your application

or

what is MVC and how do you relate it to flex apps?

22) Is it possible to make httpService Requests synchronous?(*)

A: No.Basically all service calls from flex, whether it is HTTPService, WebService or RemoteService, are asynchronous. But there are methods through which you can crack this and make these calls synchronous.

Solution 1 (I got from many sites): Create XMLHttpRequest with Javascript in Flex, and call a server data with the parameters we will give to the object.For example: xmlHttpRequest.open(GET,http://localhost/Default.aspx,false);

1. Request Type: GET or POST

2. Requested URL

3. Communication Type: true for asynchronous, false for synchronous.

Solution 2 (My Own Solution ;) ): Create one result handler for the service call and whatever processing you need to execute synchronously, put all in that result handler and BINGO!!! :)

23) I need to load an image from flickr into my application. Do I need a crossdomain.xml file on flickr?

24) Explain crossdomain.xml and why is it used?

25)Describe what the IResponder interface contains and how is it used?

26) What is the difference between httpService and Data Service? (*)

Flex allows three types of RPC services: HttpService, WebServices, and RemoteObject Services. In Flex, using the RemoteObjects specifies named or unnamed sources and connects to an Action Message Format (AMF) gateway, whereas using the HTTPService and WebService use named services or raw URLs and connect to an HTTP proxy using text-based query parameters or XML. Specifically, HTTPServices use raw HTTP requests, WebServices use the SOAP protocol and RemoteObjects uses AMF3. RemoteObject provides two advantages over HTTP or SOAP. First, while the AMF protocol uses HTTP to transfer packets, the data is transferred in a binary format that is natively understood by the Flash Player. As a result, data can move across the network more quickly and it can be deserialized more rapidly than text-based formats such as XML. Both of these result in performance gains, particularly where large sets of data are involved. Secondly, RemoteObject provides signficant productivity advantages. The remoting service, which runs on your server, automatically marshalls data between AMF and your server-side language (e.g., PHP, Java, C#). As a result, you can directly call methods on your PHP objects without having to write an XML REST interface or create web service interfaces.

27) How do you generate random numbers within a given limit with actionscript?

function randomNumber(low:Number=0, high:Number=1):Number{

return Math.floor(Math.random() * (1+high-low)) + low;

}

28) Have you built any components with actionscript? If so explain how you did it?

29)How do you implement push on a flex applications?

30)How do you implement push with flex data services?

31)I am going to add images into a tag. How will it resize itself?

32)What is a resource Manager?

33)What are the similarities between java and flex

Both can be used as client application, both have packages, OOP based , support XML , import external packages, up casting, support ArrayCollection ,almost same primitive data types, both support class library packaging( .jar , .swc).

34)How do you implement drag and drop on components that do not support ondrag and ondrop?

35)What is a drag manager?

36)Can you write to the file system from flex?

37)HOw do you call javascript from Flex?

The ExternalInterface API makes it very simple to call methods in the enclosing wrapper. You use the static call() method, which has the following signature:

flash.external.ExternalInterface.call(function_name:

String[, arg1, ...]):Object;

The function_name is the name of the function in the HTML pages JavaScript. The arguments are the arguments that you pass to the JavaScript function. You can pass one or more arguments in the traditional way of separating them with commas, or you can pass an object that is deserialized by the browser. The arguments are optional.

The following example script block calls the JavaScript f() function in the enclosing wrapper by using the call() method:

import flash.external.*;

public function callWrapper():void {

var f:String = "changeDocumentTitle";

var m:String = ExternalInterface.call(f,"New Title");

trace(m);

}

On your HTML page, you define a function as you would any other JavaScript function. You can return a value, as the following example shows:

function changeDocumentTitle(a) {

window.document.title=a;

return "successful";

}

This feature requires that the embedded movie file have an id attribute. Without it, no call from your Flex application will succeed.

The call() method accepts zero or more arguments, which can be ActionScript types. Flex serializes the ActionScript types as JavaScript numbers and strings. If you pass an objct, you can access the properties of that deserialized object in the JavaScript, as the following example shows:

public function callWrapper():void {

var o:Object = new Object();

o.lname = "Danger";

o.fname = "Nick";

var f:String = "sendComplexDataTypes";

ExternalInterface.call(f,o);

}

Flex only serializes public, nonstatic variables and read-write properties of ActionScript objects. You can pass numbers and strings as properties on objects, simple objects such as primitive types and arrays, or arrays of simple objects.

The JavaScript code can then access properties of the object, as the following example shows:

function sendComplexDataTypes(a:Object) {

alert("Welcome " + a.fname + " " + a.lname + "!");

}

You can also embed objects within objects, as the following example shows. Add the following code in your Flex applications block:

public function callWrapper():void {

var f:String = "sendComplexDataTypes";

var o:Object = new Object();

o.lname = "Danger";

o.fname = "Nick";

o.b = new Array("DdW","E&T","LotR:TS");

var m:String = ExternalInterface.call(f,o);

}

The code triggers the following JavaScript in the wrapper:

function sendComplexDataTypes(a) {

// Get value of fname and lname properties.

var m = ("Welcome " + a.fname + " " + a.lname + "!\n");

// Iterate over embedded object's properties.

for (i=0; i