Saturday, May 29, 2010

Flex 2

1.what is MVC and how do you relate it to flex apps?
A : (Separation of concerns) The goal of the Model-View-Controller (MVC) architecture is that by
creating components with a well-defined and limited scope in your application, you increase the
reusability of the components and improve the maintainability of the overall system. Using the MVC
architecture, you can partition your system into three categories of components:
* Model components Encapsulates data and behaviors related to the data.
* View components Defines your application's user interface.
* Controller components Handles the data interconnectivity in your application.

2.what is state? what is the difference between states and ViewStack?
A : The State class defines a view state, a particular view of a component. For example, a product
thumbnail could have two view states; a base view state with minimal information, and a rich view
state with additional information. The overrides property specifies a set of child classes to add or
remove from the base view state, and properties, styles, and event handlers to set when the view state
is in effect.
You use the State class in the states property of Flex components. You can only specify a states
property at the root of an application or a custom control, not on child controls.
Diff :
* View Stack is to handle different MXML file eg TAB control and states is the transition within
single MXML file.
* ViewStack should be used were there is complete change in the controls used and States should be
used when you just want to add or remove a
few components based on certain conditions.
* ViewStates are virtual state of an existing page apearing at an instance i.e. only one state can be
shown at a time
while viewStack are collection of different view containers which can be shown at a time

3.how does item renderer work? How do I add item renderer at runtime?
A : Each list control has a default mechanism for controlling the display of data, or view, and lets
you override that default. To override the default view, you create a custom item renderer.
Note: With reusable inline item renderers you use data binding to bind to the item renderer. When
you use a component as an item renderer, you do not use data binding but specify the name of the
custom component to use as an item renderer.
Add itemrendrer at run time: Create the basic item renderer. One of the things I needed to accomplish
with my item renderer was the ability to add it to different columns (ie the dataField was not always
the same). This meant I needed a way from within the renderer to determine what column it was
bound to so I could get and display the correct data. To do this the renderer needs to implement the
IDropInListItemRenderer. This interface allows the renderer to have access to information about the
list and column it is in via the BaseListData and DataGridListData classes. The DataGridListData
gives you everything you need to get the data required to make a flexible, reusable renderer.
To Modify itemrenderer at runtime we Need to use mx.core.ClassFactory. Basically, in order to
change a Flex itemRenderer at runtime, you need to cast it to a type ClassFactory.

4.What keyword allows you to refer to private variables of a class?
A : private keyword , this keyworld (?)

5.how polymorphism works on actionscript?
A:
class UnpaidIntern extends Employee
{
    override public function receivePayment():Number
    { return 0;
    }
}
class Manager extends Employee
{
    override public function receivePayment():Number
    { return baseSalary*3;
    }
}
class Engineer extends Employee
{
    override public function receivePayment():Number
    { return this.baseSalary*2;
    }
}
class Employee
{
    internal var baseSalary:Number = 1000;
    public function receivePayment():Number
    {
        return this.baseSalary;
    }
}

6.how do you overload functions in actionscript?
A : Method overloading using namespaces. (?)

7.what is dynamic keyword used for?
A: Dynamic classes, which allow you to programmatically add new properties and behavior to classes during the run-time. Just add the magic keyword dynamic to the class definition:
dynamic class Person {
var name:String;
}
Now let’s add dynamically two variables name and age and the function printme() to the object of
type Person:
Person p= new Person();
p.name=”Joe”;
p.age=25;
p.printMe = function () {
trace (p.name, p.age);
}p.printMe(); // Joe 25


8.what are sealed classes ?
A : A sealed class possesses only the fixed set of properties and methods that were defined at
compile-time; additional properties and methods cannot be added. This makes stricter compile-time
checking possible, resulting in more robust programs.

9 what are runtime shared libraries?
Macromedia Flex 1.5 you can build runtime shared libraries (RSLs) that can be individually loaded,
cached, and used by multiple applications.
Use Flex 3 runtime-shared-libraries (RSLs) to reduce the size of your applications and thereby
reduce the time required to download the application. RSLs are just SWF files whose code is used as
a shared library between different application SWF files. There are two kinds of RSLs, signed and
unsigned. Signed RSLs are libraries that are signed by Adobe and may be stored in the Flash Player
Cache, which can be accessed by applications from any domain. This means if your application is
using a signed RSL, the RSL may not even need to be downloaded if the RSL is already in the Flash
Player Cache. The signed RSL may have been put into the Flash Player Cache by visiting another
web site that was using the same signed RSL. Signed RSLs have a "swz" extension.
Unsigned RSLs are normal SWF files and are not loaded into the Flash Player Cache. Instead, these
RSLs rely on the browser's cache to keep them from being downloaded.

10.What is cairnghorm ? how do you use it?Have you worked with Cairnghorn?
A : Cairngorm is the lightweight micro-architecture for Rich Internet Applications built in Flex or
AIR. A collaboration of recognized design patterns, Cairngorm exemplifies and encourages best-
practices for RIA development advocated by Adobe Consulting, encourages best-practice leverage of
the underlying Flex framework, while making it easier for medium to large teams of software
engineers deliver medium to large scale, mission-critical Rich Internet Applications.
The benefits of the Cairngorm architecture are realized when developing complex RIA applications
with multiple use-cases and views, with a team of developers, and with a multi-disciplinary
development team that includes designers as well as creative and technical developers.
How is the MVC pattern carried out in a Flex + Cairngorm application?

- Model:???? Role of the ModelLocator & Model Objects
- View:???? Role of View Components & Event Objects
- Controller: Role of the FrontController & Command Objects

11.What keyword allows you to implement abstraction better?
A: Flex does not support abstart class directly. (?)

12.What design patterns have you used? in Actionscript and java?
A:
1. Creational Pattern
    * Factory Method Pattern
    * Singleton Pattern
2. Structural Patterns
    * Decorator Pattern
    * Adapter Pattern
    * Coposite Pattern
3. Behavioral Patterns
    * Command Pattern
    * Observer Pattern
    * Template Metod Pattern
    * State Pattern
    * Strategy Pattern
4. Multiple Patterns
    * MVC Pattern
    * Symetric Proxy Pattern

13.Explain how binding works in mxml components.
A: Binding in MXML
Lets look at the following code…
mx:TextInput id=”ti1?/>
mx:Label id=”label1? text=”{ti1.text}”/>
Here you are binding the text property of the TextInput to the label. So whatever you type in the
textInput automatically reflects in the label. That’s the power of Binding…
The best practice for defining components that return information back to the main application is to
design the component to dispatch an event that contains the return data. In that way, the main
application can define an event listener to handle the event and take the appropriate action. You also
use events in data binding. The following example uses the Bindable metadata tag to make
useShortNames a bindable property. The implicit setter for the useShortNames property dispatches
the change event that is used internally by the Flex framework to make data binding work.

14.What’s the difference between ChangeWatcher. watch, and BindingUtils.bindProperty?
A: ChangeWatcher: 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.

15.Why would you want to keep a reference to a ChangeWatcher and call unwatch()?
A: So we can reattach the watcher again & We can change the source object (of changewatcher) by reset method.
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

16.How do you add event listeners in mxml components. Now AS3 components?
A:
* addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
* removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
* dispatchEvent(event:Event):Boolean
* hasEventListener(type:String):Boolean
* willTrigger(type:String):Boolean

17.What does calling preventDefault() on an event do? How is this enforced?
A: Cancels an event's 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.

18.Explain the lifecycle of a Cairngorm action.
A: Here’s a normal flow of operations and the Cairngorm classes that are exercised.



When the user takes some sort of action on the view, such as clicking a button, the view dispatches a CairngormEvent. This event informs the FrontController, which instantiates a Command. The command executes the business logic, and the event is responsible for passing data to the command about the user interaction. The command can either take some action on the Model, or instantiate and act on a BusinessDelegate. The Business Delegate, or delegate for short, wraps the code required for a service call, so
it acts like the service API to the rest of the application. This is important because when the service changes, the changes to the application can be minimized and ideally only the delegate needs to
change. The delegate calls the service and then depending on the kind of service involved makes sure
that the command is informed when the service call has returned. Then the command changes the
state of the model, if necessary, and the model, through Flex’s binding, updates the view.

19.Explain the difference between creating an effect and setting the target as opposed to adding an effectListener
A: To create a behavior, you define a specific effect with a unique ID and bind it to the trigger.
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>

20.How do you identify a component created in a repeater?
A: If currentIndex value is greater than startIndex value means a component is created in Repeater.
We can use count property to find number of children.
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 itsdataProvider,startingIndex, orcount
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 therecycleChildren property is set tofalse), and then reinstantiates its children based
on the currentdataProvider property.

21.Differences between defining bindings in MXML and ActionScript?
A: There are a few differences between defining data bindings in MXML at compile time and in
defining them at runtime in ActionScript:
* You cannot include ActionScript code in a data binding expression defined by the bindProperty()
or bindSetter() method. Instead, use the bindSetter() method to specify a method to call when the
binding occurs.
* You cannot include an E4X expression in a data binding expression defined in ActionScript.
* You cannot include functions or array elements in property chains in a data binding expression
defined by the bindProperty() or bindSetter() method. For more information on property chains, see
Working with bindable property chains.
* The MXML compiler has better warning and error detection support than runtime data bindings defined by the bindProperty() or bindSetter() method.

No comments:

Post a Comment