Jul 07

Flex coding standards and best practices

Posted by James Netherton | Monday 07 July 2008 1:00 PM | In Flex

Adobe have added a list of Flex standards and best practices on their open source wiki.

Apparently it's not 100% complete yet but it's a nice set of guidelines nonetheless.

http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions

 

Feb 15

Issues with Flex DataGrid and custom ItemRenderers

Posted by James Netherton | Friday 15 February 2008 6:48 PM | In Flex

I've just finished implementing a work around for some problematic behaviour I came across within the Flex DataGrid. I have a user interface which has a DataGrid with custom item renderers so that combo boxes can be rendered within DataGrid cells. In order to set the combo box selected index to it's appropriate value, I was invoking some custom code on the combo creationComplete event.

Some freaky things were happening when data within the grid was being refreshed. Some of the combo selected values were not in the order I expected them to be in.

After doing some digging, it seems that DataGrid ItemRenderers are reused for performance reasons. This is a problem if using the creationComplete event.

The solution is to override the container 'data' setter property method, with an implementation like the following:

public override function set data(value:Object):void{

super.data = value;

if(value == null){
return;
}

//Further custom logic here....
}

There's a great overview of the problem over at Steve Kamerman's Blog. There's also a nice working example here.

Some other blog posts that helped are:

Flex DataGrid ItemRenderers Explained

Item Renderers in DataGrids - A Primer for Predictable Behavior

 

Jan 27

Installing Flex Builder 2 with Eclipse 3.3

Posted by James Netherton | Sunday 27 January 2008 2:29 PM | In Flex

I've just suffered the pain in trying to get Flex Builder 2 integrated with Eclipse 3.3.

The answers to getting it configured sucessfully are within this article at Eclipse Zone

 

Aug 30

ActionScript ColdFusion variable translation

Posted by James Netherton | Thursday 30 August 2007 5:10 AM | In Flex,ColdFusion

Thought I would post this as I can never track down this information via livedocs.

Here's what data type ColdFusion variables get converted to in ActionScript when making remote calls to CF services:

ColdFusion data type      ActionScript data type
String String
Array Array
Struct Untyped Object
Query Array of untyped Objects
CFC Class typed Object
CFC Date ActionScript Date
CFC String ActionScript String
CFC Numeric ActionScript Numeric
ColdFusion XML Object ActionScript XML Object

 

Aug 10

Change to services-config.xml in ColdFusion 8

Posted by James Netherton | Friday 10 August 2007 2:19 PM | In Flex

I'm not sure whether this changed in the ColdFusion 8 release candidate or in the final release.....

A subtle change has been made to services-config.xml from the format that has been used since ColdFusion 7.0.2 and through the ColdFusion 8 beta releases.

The Flash Remoting definition for ColdFusion has been moved out of services-config.xml to a separate XML file named remoting-config.xml.

Something to be aware of if you're writing applications that aren't using their own individual config files.

 

May 15

Flex Builder memory usage

Posted by James Netherton | Tuesday 15 May 2007 9:16 AM | In Flex

Flex Builder Memory Usage

A quick Flex Builder rant.....

Above is the typical amount of memory usage and swap space that Flex Builder uses on my work machine.

I've seen it way higher than that on some occasions. What the hell is the thing doing to eat up that much RAM? Flex Builder consumes around 200Mb - 250Mb RAM until you enter design mode, which seems to gobble up another 50Mb - 100Mb.

It's annoying - maybe there are some JVM tweaks that will help.

 

Mar 08

Cairngorm Eclipse Plugin

Posted by James Netherton | Thursday 08 March 2007 8:17 PM | In Flex

This looks awesome!

Introducing Cairngorm Plugin

If only this were around a few months ago! It would have made development of a Flex application I'm working on, a breeze! Check out some of the screen shots over at the site.

 

Feb 28

Flex stack overflow gotcha

Posted by James Netherton | Wednesday 28 February 2007 3:20 AM | In Flex

I finally got to the bottom of what was making FlashPlayer crash with a piece of code I had in one of my apps. Turns out I was getting stack overflow exceptions as a result of an event firing repeatedly.

Here's an example application which explains what I was doing:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="setData()">
   
   <mx:Script>
      <![CDATA[
         import mx.events.DataGridEvent;
         import mx.collections.ArrayCollection;
         
         [Bindable]
         private var gridData:ArrayCollection = new ArrayCollection();
         
         private function setData():void
         {
            for(var i:Number = 1; i < 10; i++)
            {
               var obj:Object = new Object();
               obj.id = i;
               obj.name = "Name " + i;
   
               gridData.addItem(obj);
            }
         }
         
         private function validateEdit(event:DataGridEvent):void      
         {
var newVal:String = event.currentTarget.itemEditorInstance.text;            
            
            if(newVal.length > 150 && event.reason == "newRow")
            {
               mx.controls.Alert.show("Value cannot exceed 150 characters in length");
               return;
            }
         }

      ]]>
   </mx:Script>
   
   <mx:DataGrid width="100%"
             height="100%"
             dataProvider="{gridData}"
             itemEditEnd="validateEdit(event)"
             editable="true">

      <mx:columns>
         <mx:DataGridColumn dataField="id" headerText="Person Id"/>         
         <mx:DataGridColumn dataField="name" headerText="Person Name" editable="true"/>         
      </mx:columns>
   </mx:DataGrid>   
      
</mx:Application>

It's quite straightforward. I populate a DataGrid component with some dummy data. The person name column is made editable. Whenever a value is entered into the DataGrid cell the validateEdit method traps the itemEditEnd event and checks to see whether the string entered was greater than 150 characters.

If the condition evaluates to true, an Alert box is displayed.

Run the application, click one of the editable DataGrid cells and enter a string longer than 150 characters, the result should be that your browser or Flash Player will crash.

Now add a trace statement into the validateEdit method:

trace(event.reason)

Run the application again and enter another string longer than 150 characters into the editable DataGrid cell.

The application will crash again, but the trace output should reveal that the itemEditEnd event was fired over a hundred times which means that the Alert popup will be attempted to be displayed each time - obviously not very performant and hence the stack overflow!

The trace also reveals that all of the event reasons were for type 'other', but the actual item edit event was for type 'newRow'.

So the solution is quite simple, we simply add an extra condition into the if statement that checks the character length.

if(newVal.length > 150 && event.reason == "newRow")

Rerun the application and hopefully no more stack overflow errors will occur :).

 

Jan 30

have you tried rebooting?

Posted by James Netherton | Tuesday 30 January 2007 10:09 PM | In Flex,ColdFusion

"Have you tried rebooting?" - The usual first question from any desktop support engineer.....

I'll probably have to create a category that contains my experiences of trying to debug problems that don't exist.

Today at work a new server was built to host a Flex project I've been working on. Strangely the basic install of ColdFusion was only 7.0 so I went through the process of installing 7.0.1 & 7.0.2.

So I uploaded my code not entirely expecting everything to work first time and up popped the dreaded "send failed" message.

2 hours later I still couldn't figure out why flex wasn't talking to the new CF server. I'd messed with services-config.xml, crossdomain.xml and restarted the CF services but nothing worked.

I then used Microsoft Fiddler to see what was going on behind the scenes. The flex app was getting 404's when it made calls to the server's flex2gateway. Weird I thought everything seems to have installed ok.

As I was about to give up and go home to research the problem, I decided to reboot the server and sure enough afterwards, my app started to work!

Could have saved myself a couple of hours worth of time wasting...

 

Jan 29

AMFPHP 1.9 beta 2 released

Posted by James Netherton | Monday 29 January 2007 8:16 PM | In Flex

The beta 2 of AMFPHP 1.9 has been released to the claim of:

amfphp the fastest Remoting implementation ever

The performance figures are truely impressive. Time I started having a mess around with getting PHP talking with Flex 2 methinks...