Saturday, May 29, 2010

Flex 3

1.What are the methods called when a UI component is intialized?
createChildren()

2.What is a drag manager? The DragManager class manages drag and drop operations, which let you move data from one place
to another in a Flex application. For example, you can select an object, such as an item in a List
control or a Flex control, such as an Image control, and then drag it over another component to add it
to that component.
All methods and properties of the DragManager are static, so you do not need to create an instance of it. All Flex components support drag and drop operations. Flex provides additional support for drag and drop to the List, Tree, and DataGrid controls. When the user selects an item with the mouse, the selected component is called the drag initiator. The image displayed during the drag operation is called the drag proxy. When the user moves the drag proxy over another component, thedragEnter event is sent to that component. If the component accepts the drag, it becomes the drop target and receivesdragOver, dragExit, and dragDropevents. When the drag is complete, adragComplete event is sent to the drag initiator.

3.How do you call javascript from Flex?
The ExternalInterface class is the External API, an application programming interface that enables
straightforward communication between ActionScript and the Flash Player container– for example,
an HTML page with JavaScript. Adobe recommends using ExternalInterface for all JavaScript-
ActionScript communication.
You can call an ActionScript function in Flash Player, using JavaScript in the HTML page. The
ActionScript function can return a value, and JavaScript receives it immediately as the return value
of the call.
This functionality replaces thefscommand() method. The ExternalInterface class requires the user's web browser to support either ActiveX® or the
NPRuntime API that is exposed by some browsers for plug-in scripting. Even if a browser and
operating system combination are not listed above, they should support the ExternalInterface class if
they support the NPRuntime API.
Note: When embedding SWF files within an HTML page, make sure that theid andname attributes of theobject andembed tags do not include the following characters: . - + * / \
From ActionScript, you can do the following on the HTML page:
 • Call any JavaScript function.
• Pass any number of arguments, with any names.
• Pass various data types (Boolean, Number, String, and so on).
 • Receive a return value from the JavaScript function. From JavaScript on the HTML page, you can:
• Call an ActionScript function.
• Pass arguments using standard function call notation.
• Return a value to the JavaScript function.
Flash Player does not currently support SWF files embedded within HTML forms.

4.How do you use a repeater?
The Repeater class is the runtime object that corresponds to the mx:Repeater> tag. It creates
multiple instances of its subcomponents based on its dataProvider. The repeated components can be
any standard or custom controls or containers.
You can use the mx:Repeater> tag anywhere a control or container tag is allowed, with the exception of the mx:Application> container tag. To repeat a user interface component, you place its tag in the mx:Repeater> tag. You can use more than one mx:Repeater> tag in an MXML document. You can also nest mx:Repeater> tags.
You cannot use the mx:Repeater> tag for objects that do not extend the UIComponent class. MXML Syntax
 The  Repeater> class has the following properties: 
mx:Repeater Properties id="No default" childDescriptors="No default" count="No default" dataProvider="No default" recycleChildren="false|true" startingIndex="0" Events repeat="No default" repeatEnd="No default" repeatStart="No default" >

5.What does calling preventDefault() on an event do? How is this enforced? public function preventDefault():void Cancels an event's default behavior if that behavior can be canceled. Many events have associated behaviors that are carried out by default. For example, if a user types a
character into a text field, the default behavior is that the character is displayed in the text field.
Because theTextEvent.TEXT_INPUT event's default behavior can be canceled, you can use the preventDefault() method to prevent the character from appearing. An example of a behavior that is not cancelable is the default behavior associated with the Event.REMOVED event, which is generated whenever Flash Player is about to remove a display object from the display list. The default behavior (removing the element) cannot be canceled, so the preventDefault() method has no effect on this default behavior. You can use theEvent.cancelable property to check whether you can prevent the default behavior associated with a particular event. If the value ofEvent.cancelable istrue, then preventDefault() can be used to cancel the event; otherwise, preventDefault() has no effect.
![CDATA[ private function textArea_textInput(evt:TextEvent):void
{ if (evt.text == "\n")
{ evt.preventDefault(); }
} ]]>
/mx:Script>
mx:TextArea id="textArea" verticalScrollPolicy="on" width="160"
height="120" textInput="textArea_textInput(event);">
mx:text>The quick brown fox jumped over the lazy dog.
/mx:text>
/mx:TextArea>

6.LifeCycle of Flex-application??

initializedproperty
initialized:Boolean[read- wri te]
A flag that determines if an object has been through all three phases of layout: commitment, measurement, and layout (provided that any were required).
Ex:
    ?xml version="1.0" encoding="utf-8"?>
    mx:Applicationx mlns:mx="http://www.adobe.com/2006/mxml"     layout="absolute"width="349" height="319"     viewSourceURL="../files/LifeCycleEventsTutorial.mxml"     preinitialize="recordEvent(event)" initialize="recordEvent(event)"     creationComplete="recordEvent(event)"     applicationComplete="recordEvent(event)">
     mx:Script>
     ![CDATA[ importmx.ev ents.FlexEv ent;
     importflash.ut ils.getTimer;
     [Bindable]
     privatevarreportTxt:String= "";
     privatefu nctionrecord Event(event:F lexEvent):void
     { reportTxt += (event.type + " event occured at " +      flash.utils.getTimer() +" ms" +"\n"); } ]]>
     /mx:Script>
     mx:Panelx="0" y="0"width ="349"heigh t="319" layout="absolute"      title="Life Cycle Events">
     mx:TextAreax="10" y="10"width ="309"heigh t="259" editab le="false"      id="txtReport" text="{reportTxt}"/>
     /mx:Panel>
     /mx:Application>
7.Can I dynamically instantiate a WebService or HTTPService in ActionScript?
Flex 1.5 does not support this. First declare the tags in MXML and then manipulate the URLs, request objects, and so forth using ActionScript.

8. Can I load CSS style sheets dynamically at runtime?
Dynamic loading of CSS files is not supported in Flex. CSS in Flex is processed on the server side during MXML compilation rather than on the client side at runtime. There is a trick though: A CSS file can be compiled into a separate SWF file and loaded dynamically into the application using the Loader component.

9.When I setvisible="false", the component still takes up space and appears in the tab order. Why is that?
You can often achieve the "display=none" effect by setting the height/width to zero when you set it invisible, and then set it back to a fixed value or toundefined when you make it visible again.

10.Why are my ValueObject member variables undefined in the results from my RemoteObject requests?
A.Flash Player deserializes objects in a special order that can confuse developers used to object serialization from other RPC systems. When a strongly typed object is returned to the player, it first creates an instance from the prototype of the registered class without calling the constructor. It then
populates the object with the properties sent in the result. Finally, it calls the constructor without arguments. If your ValueObject constructor expects arguments to initialize an instance, be sure to check whether arguments were actually sent to the constructor before overriding member variable values.

11.Why do strongly typed objects appear as "undefined" in the NetConnection Debugger?
The NetConnection Debugger is an old utility from the early days of Flash Remoting that some developers still find useful. It has an issue, however, displaying types that have been registered with Object.registerClass(). If your Flex server is installed locally, we suggest enabling server-side "debug" level logging in /WEB-INF/flex/gateway-config.xml to watch the raw trace information in the Flex server console/logs from the AMF Gateway as it processes your RemoteObject requests. Flex Builder also includes a Network Debugger that allows you to monitor AMF traffic.

12.How do I get access to the J2EE session from my RemoteObjects? The AMF Gateway provides access to the currentHttpServletRequest instance in a thread local variable. The session can be obtained from the request, as follows: flashgateway.Gateway.getHttpRequest().getSession();

13.Can I resize the Internet Explorer browser window from Flex?
UsegetURL() to communicate with JavaScript in the HTML wrapper: getURL('javascript:window.resizeTo(1050,900)');

14.Can Flex applications communicate with each other on the client?
See theLocalConnection API in the documentation.

15.Is double-clicking supported on various components?
A.Unfortunately, double-clicking is not supported by default. If you wish to add this functionality to, say, a List or DataGrid component, you will have to add the following ActionScript 2.0 code to your application:
var someTimestamp:Number;
public function doubleClickHandler( evt:Object ):Void {
var now = getTimer();
// we got a double-click
if( ( now - someTimestamp ) < 500 ) {
// do something here ... }
someTimestamp = now; }

16.Why are there errors with the macromedia.css.LocatorParser class and WebLogic? WebLogic ships with its own version of the fop.jar, which in turn includes the batik.jar, which is older and breaks Flex. To resolve this issue, remove the fop.jar from the CLASSPATH in the startWebLogic.cmd file. This may apply to non-WebLogic servers as well, where batik.jar was included.

17.What does "The URL is not in the Proxy's whitelist" mean?
The whitelist is a security feature in Flex that requires you to define explicitly which URLs a data service call can access.
You set this by editing the following file: ...\[flexroot]\WEB-INF\flex\flex-config.xml
There are three sections, one each for WebService, HTTPService, and RemoteObject. Be sure you edit the correct section! Each has a subsection which contains nodes. To enable a URL for access by a Flex dataService call, enter that URL between the tags. For development phaseonly, you can allow global access with the wildcard rows. The flex-config file is heavily commented. Open it up and you will see more detailed instructions there.

18.Sometimes, if I don't move the mouse, "click" and "mouseDown" don't work. Why is that?
This is a focus issue with Flash Player; usually when the UI changes "underneath" the mouse pointer, as in a ViewStack navigation where the buttons are in the same screen location.

19. Why ismyTreeNode.label ormyTreeNode.attributes.label undefined?
Make sure you use theTreeDataProvider methods to modify a node. Don't rely on the node being XML. For example, the above should bemyTreeNode.getProperty("label") instead.

20.When I add or modify an item in my dataProvider, why doesn't it show up in my DataGrid?
Low-level methods likeArray.push() or myArray[0] = "whatever" do not cause the
dataProvider'smodelChanged event to fire. When you work with a dataProvider, it is always best to use the dataProvider API. In the above example, you might code:myDataProvider.addItem(myItemObject) to add an item or use editField() to modify a value programmatically. Alternatively, you can callmyDataProvider.modelChanged yourself or reassigndataProvider to the control, as follows: myDataGrid.dataProvider = myDataProvider;


No comments:

Post a Comment