Even as developers start to experiment with Flex 2 through Labs, there are still many questions that are frequently asked about developing Rich Internet Applications with Flex. With that in mind, key members of the Flex community and engineers on the Flex engineering team worked to update the technical FAQ for Flex.
The original technical FAQ for Flex appeared on the Flexcoders website at http://groups.yahoo.com/group/flexcoders/message/24352. Flexcoders is a mailing list that consultants at iteration::two started in 2004. The list continues to be a thriving resource on all current Flex questions and development solutions.
Then in 2005 Tariq Ahmed continued to update the Flexcoders technical FAQ at http://www.cflex.net/showfaq.cfm.
In both cases, and here in this article, developers focusing on creating Rich Internet Applications with Flex and other technologies contributed their technical questions and solutions to the Flex community.
visible="false", the component still takes up space and appears in the tab order. Why is that? myTreeNode.label or myTreeNode.attributes.label undefined?Check the Flex product page for up-to-date information.
Adobe has not announced a date.
Go to http://www.mail-archive.com/flexcoders@yahoogroups.com.
The "Integrated JRun" install does not support IIS connectors. If you are using full JRun or ColdFusion, visit the link below:
http://www.macromedia.com/go/96611248
For other application servers, see their respective documentation.
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.
See the simple "Beginner's Tips" examples on www.cflex.net, and see the Cairngorm Framework's Service Locator pattern for a more fully realized solution.
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. Read more about this topic on Manish Jethani's blog at http://www.livejournal.com/users/mannu/286686.html.
visible="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 to undefined when you make it visible again.
To report a bug or request an enhancement, go to http://www.macromedia.com/go/wish.
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.
Note: Flash Player does not currently honor getter/setter properties in object serialization or deserialization.
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.
The AMF Gateway provides access to the current HttpServletRequest instance in a thread local variable. The session can be obtained from the request, as follows:
flashgateway.Gateway.getHttpRequest().getSession();
Use getURL() to communicate with JavaScript in the HTML wrapper:
getURL('javascript:window.resizeTo(1050,900)');
Note: This solution has been tested only in Internet Explorer.
See the LocalConnection API in the documentation.
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:
// used to detect a double-click
var someTimestamp:Number;
...
/**
* Double-click handler for some DataGrid component.
*/
public function doubleClickHandler( evt:Object ):Void {
var now = getTimer();
// we got a double-click
if( ( now - someTimestamp ) < 500 ) {
// do something here ...
}
someTimestamp = now;
}
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.
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 phase only, 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.
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.
One workaround is to add the following property to the Button tag:
trackAsMenu="true"
Flex—or, more correctly, Flash Player—has the notion of a context menu that you can configure. Check out the Flex LiveDocs for details about the ContextMenu class:
http://livedocs.macromedia.com/flex/15/flex_docs_en/00001276.htm
However, there is a limitation of the current player (Flash Player version 7 and earlier) where the context menu can only be shown on components inside the root container (such as mx.core.Application.application). You can get around this by having the context menu on the root object and changing it dynamically at runtime depending on which component the mouse is over—but this is a bit more work for you.
myTreeNode.label or myTreeNode.attributes.label undefined?Make sure you use the TreeDataProvider methods to modify a node. Don't rely on the node being XML. For example, the above should be myTreeNode.getProperty("label") instead.
Low-level methods like Array.push() or myArray[0] = "whatever" do not cause the dataProvider's modelChanged 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.
See dataProvider in the Flex LiveDocs: http://livedocs.macromedia.com/flex/15/asdocs_en/index.html
Alternatively, you can call myDataProvider.modelChanged yourself or reassign dataProvider to the control, as follows:
myDataGrid.dataProvider = myDataProvider;
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 tree DataProvider API. These methods will work for any format dataProvider 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");
See dataProvider and treeDataProvider in the Flex LiveDocs:
This is technically possible. However, the Flex 1.5 license requires the presence of a Flex server, and the SWFs compiled using the Developer version of Flex expire in one day. Review the license carefully.
If you have a special business case for doing this, contact your Adobe sales rep; they are often willing to discuss special agreements.
Tracy Spratt has put together a very simple example that you can download here:
You can read more details regarding this solution at: http://www.cflex.net/showfiledetails.cfm?objectID=197
Don't panic. Your application is not too big for Flex to handle. True, the 32K limit is really a Flash Player limitation to the size of certain structures, such as if blocks and for loops. But you don't really care about that right now because you don't have any direct control over those things. Here is some information that will help you get back to coding.
There are two main reasons why you might encounter the 32K issue. The primary cause—and the one to address first—is the architecture of your application code. The 32K error message asks you to "refactor" your code. Refactoring is essentially the process of modifying the structure of your source code while keeping the same functionality. In the Flex world, this means moving some parts of the code out of a main file and into separate components.
One way to do this is to use custom MXML components. So instead of, say, having several hundred lines of MXML in a child container of a ViewStack, you put that MXML code into its own component file and have just a single line in the ViewStack reference it. If you do that for all the ViewStack children, 1000 lines of code can easily become 30. Decreasing the total number of visually rendered MXML tags in a single file will help avoid the 32K limit. Another type of refactoring is to move ActionScript code into its own class.
Important note! Just putting the ActionScript code into a file and then using the #include directive or the mx:Script source="myscript.as" method to include the code will not help with the 32K problem. You must create a true ActionScript class that contains the functionality. At 2000 lines of mixed MXML and ActionScript code, you are in danger of the 32K error. We have not found an upper limit whatsoever to code length in a class.
The second cause of the 32K error is not your fault. During compiling, Flex generates ActionScript code out of your MXML source. It then compiles that into the Flash SWF file. During that process it decides how to break up your source code and generate the ActionScript class code. In Flex 1.5 it doesn't always make the right decision, and so the result is the 32K error.
If you are confident that your application is already efficiently "refactored," and you suspect that you might be at one of these boundary conditions, first try compiling the app with ?debug="true" in the URL. If the app compiles, then you are surely at a boundary condition. What happens is that debugging adds code to your source during generate/compile. This additional code causes Flex to change the structure of the ActionScript classes so that the application does not reach the 32K limit. Hmm, more code? Yeah. Try just adding 50 or so lines of code, even if it is bogus code. Usually, this will get you working. When you add more real code, remove the bogus code because you won't want that in your production code!
We have found a third cause of the 32K limit error: There are some syntax errors that get by the compiler, yet cause the 32K limit error. At this time there is no example of the kind of syntax that can cause this problem, but you should be aware that it is possible.
A final hint: After hitting a 32K error and trying one of the previously described solutions, and if the error still occurs, delete the temporarily generated ActionScript code. It is located in ..\MyAppServer\flex(flexroot or contextroot)\WEB-INF\flex\generated\*. You can delete all the folders safely (make sure to restart your Flex server).
This can be an aggravating and somewhat scary problem, and it always seems to happen just before an important demonstration. Just use good, modular design and remember the bogus code trick. Adobe has stated that it is committed to improving this situation in the next release.
Generally speaking, binding needs type information to set up its change detection functionality. Anything that hides this information can cause this problem. Here are some ways around this problem:
mx.core.application.application.myVariable in binding.text="{String(myObject.whatever.firstName)}"With the current Flex 1.5 component set, there is no Rich Text Editor. There are some limitations in the current version of Flash Player (Flash Player 7 and earlier) that make such an editor difficult, although there are implementations that people have used. Adobe has heard many requests for a Rich Text Editor and has indicated that there might be better support for it in a future release.
There is a third-party component called FlashTextEditor that you can integrate.
There are plans for Flex 2 to include the mx:RichTextEditor tag.
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.
Probably. Search the archives if you have a specific question about your platform before posting to the list.
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:
You are probably trying to read the result immediately after the send(), right? You're expecting synchronous behavior? You can't do this. See the next question, "How do I make synchronous data calls?"
You cannot make synchronous calls. You must 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:
onResult().result property and pass "event" in too.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()
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 the sQueryId value in a switch to do the correct processing. Alternatively, you can pass reference to a handler function directly.
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 to always use toArray(), 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)
Actually, it is worse than that. Alerts and "modal" pop-up windows are not truly modal. They prevent user interaction with the interface, but they do not block code execution. What happens is that both alerts appear; the second one on top of the first.
To get the behavior you want, use events and handlers. Your code must display the alert, or modal pop-up window, and then end. When the user dismisses the prompt, you then complete the processing. You should be able to find some examples of how to do this on one of the sites listed in the Resources section of cflex.net.
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 using DataGridColumn tags. See the Flex LiveDocs for more information about this.
Flex supports a limited subset of HTML in its TextArea and some other text-related classes.
There is also a new article by Christophe Coenraets on his blog discussing how to fake HTML with an IFRAME: http://coenraets.com/viewarticle.jsp?articleId=95
For Flex 1.5: To improve Flex Builder performance, it is best to disable the Design view. This can only be done in Flex Builder 1.5. To do so, please follow these steps:
For Flex 2: Deselect the Build Automatically option. Deselect Project > Build Automatically option from the menu and you will see an increased performance, especially during save operations. Also, if you're not using a project, make sure you close it, making more memory available.
The safest way to set breakpoints in component files is to use the Files list. Start the debugging session, navigate in your application to where you want to start debugging. Click the Files button on the Debug Toolbar (select Menu Debug > Files). Select the component you want, usually the MXML or ActionScript files.
The list strips out underscores in filenames and can be very long, but this method always works. Flex Builder will open a temporary file and set the breakpoints. Now you can proceed.
Yes there are:
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:
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" width="425" height="400">
<mx:Style>
@font-face
{
fontFamily:myfont;
src:url("file:///c:/windows/fonts/Georgia.TTF");
}
</mx:Style>
<mx:Canvas>
<mx:Label fontFamily="myfont" fontSize="16" id="out" _rotation="90" text="This is a label" alpha="20"/>
</mx:Canvas>
</mx:Application>
See the following resources:
Yes, see the following resources:
There is no direct way to call an ActionScript function from JavaScript with Flex 1.5 applications running Flash Player 7. Flash Player 8 has a new feature called ExternalInterface that allows two-way communication between ActionScript and JavaScript.
Because Flex 1.5 applications cannot take advantage of some of the new features in Flash Player 8, see the following resources: