Saturday, May 29, 2010

Flex 4

1.myTree appears just fine but why can't I access the node attributes?
Select a node in your myTree. In ActionScript, you can reference this node by using the following code:
myTree.selectedNode;
To access the attributes of the node, use the treeDataProvider API. These methods will work for any formatdataProvider item, which might be an object, array, or XML node. The following example might work:
myTree.selectedNode.attributes.myAttribute
But the following example is far more reliable:
myTree.selectedNode.getProperty("myAttribute");

2.How do I pass parameters to a pop-up window? Three different ways to pass data into a title window. It uses the initobj to pass in several built-in properties plus two user defined properties. One is a simple string, the other is a reference to the main application that can
be used for binding. Note the variable that holds the application reference is
typed to the name of the application. this is critical for binding to work
correctly.

3.How do I run Flex as a service?
Flex is not a server that you deploy and run. It is simply deployed as part of your web application. So it will work, no matter which web container you are using: Tomcat, JRun 4, WebLogic, and so forth. To learn how to deploy Tomcat, JRun 4, or any other Java server as a service, refer to the appropriate documentation for the server you are using.

4.How do I get Flex to query my database? Flex does not have any native database integration functionality. You must have your own server-side
tier that provides the database-access tier and sends the data back to Flex through one of the
following protocols:
• RemoteObjects: This is the fastest. It communicates with server-side EJBs or POJOs using AMF, a binary compressed format.
• HTTPService: This one uses the HTTP protocol. Sources can be JSP, ASPx, .NET, or any URL that returns HTTP.
• WebService: This is the slowest. It uses the SOAP protocol. Sources can be .NET or any web service

5.How do I make synchronous data calls?
You cannot make synchronous calls. Youmust use the result event. No, you can't use a loop, setInterval, or even doLater. This paradigm is quite aggravating at first. Take a deep breath, surrender to the inevitable, resistance is futile.
There is a generic way to handle the asynchronous nature of data service calls, called ACT (Asynchronous Call Token). Search for this in the Developing Flex Applications LiveDocs for a full
description.
Here it is in a nutshell. This example uses HTTPService but will be similar for RemoteObject and WebService:
1. Create a function to handle the data return, likeonResult().
2. In the HTTPService tag, put this function name in theresult property and pass "event" in too.
3. Invoke the call in the script: //invokes the call to the HTTP data service
var oRequestCallbject = app.mxdsGetData.send(oRequest);
//Next, define a string to identify the call. We will use this string value
in the result handler.
oRequestCall.MyQueryId = "WhateverIWanttoUseToIdentifyThisCall" ; //Yes, you CAN set this AFTER you invoke send()
4. In the result handler, which will be called every time the data service call returns, identify what the returned data contains, as follows: var callResponse = oEvent.call; //get the call object
//gets the value of this property you set in the call
var sQueryId = callResponse.MyQueryId; //will be
"WhateverIWanttoUseToIdentifyThisCall";
trace(sQueryId);
You can use thesQueryId value in a switch to do the correct processing. Alternatively, you can pass reference to a handler function directly.

6.When I have only a single record, why doesn't it appear in my DataGrid?
This is a known issue that is caused by the inability of Flex to differentiate between an object and an
array with a single row. The solution is toalways usetoArray(), as in the following examples:
In MXML:
{mx.utils.ArrayUtil.toArray(modelAccidents1.accidents.accident)}
The inline format: dataProvider={mx.utils.ArrayUtil.toArray(testSrv.result.result.error)}
In ActionScript: myControl.dataProvider = mx.utils.ArrayUtil.toArray(testSrv.result.result.error)

7.Why are the columns in my DataGrid in some strange order?
The order is typically the reverse of the order in which they were added. If you need a specific order, specify that and many other good things by usingDataGridColumn tags.

8.Can I embed HTML in my Flex application?
Flex supports a limited subset of HTML in itsTextArea and some other text-related classes.

9.Are there frameworks available for Flex?
Yes there are:
• Cairngorm:http
• FlexUnit
• SynergyFLEX:http
• ARP
• AsUnit

10.Is vertical text possible in Flex?
Yes, that is possible. You have to embed the font outlines and then use the_rotation property of the control. For example, you can use the Label_rotation property. But you would need to embed the font if you want to rotate a Label, TextInput, or TextArea:

11. Flex component life cycle:
Initialization Stage :
a) Construction Stage (Initialization Phase): In this stage of initialization Phase, the constructor of the component is called by component tag in MXML
or usingnew operator . We can use this stage to;
1) Set some of initial values for the component properties.
2) To add event listeners to the component.
3) And initialize the other objects.

b) Configuration Stage (Initialization Phase): This stage occur only once in component life cycle. During this step the values assigned for properties of the component using setters are set internally to refer them later in configuration of component.
c) Attachment Stage (Initialization Phase): This stage of Initialization Phase gets triggered when component is added to the display list using either addChild(), addChildAt() Or component created in MXML tags. In this stage the components parent is defined because the component is now added to the display list. When this component is added to display list it calls initialize () method to initiate the next stage of this phase, i.e. Initialization Stage.
d) Initialization Stage (Initialization Phase): After component is attached (Attachment Stage) to the display list, initialization Stage starts. This is
important Stage of the component life cycle. This is responsible to create children objects of the component,
sizing and placing the component and its children, and applying the property, style values to the component.
During this stage following steps occurs;
Step1: Dispatch preinitialize event.
Step2: Callscreat eChildren() method to create children of the component.
Step3: DispatchInitia lize event
Step4:Inval idation: Marks the component for Invalidation which results the component to go with methods
invalidateProperties(), invalidateSize()and invalidateDisplayList(). (We see more about Invalidation after some lines) Step5:Val idation: Invalidation of last step results to validation methods like commitProperties(), measure() andupdateDisplayL iIst().(we see more about Validation after some lines)
Step6: Dispatch creationComplete event.

No comments:

Post a Comment