Flex howto: DataGrid sorting and labeling

First, the data going into my DataGrid. I have three objects

Discipline ... Employee ... Step

The Discipline object has an EmployeeID and StepID. Discipline also has EmployeeObject and StepObject, which are the full Employee and Step objects that match the IDs in the Discipline object. It's a lot simpler than it might sound.

[More]

Flex selectComboBox(), mkII

At the suggestion of a coworker, I've made a tiny change to my selectComboBox() function. The purpose of this function is to automatically select something in a ComboBox, such as if you're editing a form. But what if the function ends up doing nothing because no matches were found? Now it'll return false in that case. Also I properly capitalized it.

[More]

Flex modules == win

Those using FlexBuilder3 will have noticed a new option in File>New. MXML Module! They're badass. I tried to explain what a module is yesterday, and failed terribly. So I'll copy/paste from the livedocs...

LiveDocs link


Modules are SWF files that can be loaded and unloaded by an application. They cannot be run independently of an application, but any number of applications can share the modules.

Modules let you split your application into several pieces, or modules. The main application, or shell, can dynamically load other modules that it requires, when it needs them. It does not have to load all modules when it starts, nor does it have to load any modules if the user does not interact with them. When the application no longer needs a module, it can unload the module to free up memory and resources.

Modular applications have the following benefits:

  • Smaller initial download size of the SWF file.
  • Shorter load time due to smaller SWF file size.
  • Better encapsulation of related aspects of an application. For example, a "reporting" feature can be separated into a module that you can then work on independently.


Drop in a ModuleLoader. Search livedocs for the CustomModuleLoader component, it's nice

<mx:ModuleLoader id="modLoad"/>

Load a module into it. Pass this function the URL to the module's swf

private function switchApps(module:String):void{
   modLoad.url = module;   
}

Call a public function within the module. Note I type cast the loaded module here

private function treeClicked(evt:Event):void{
   (modLoad.child as disciplineModule).treeClicked(evt);
}

Benefit to using CFC Gateways with Flex, #127

If you follow the OO methodology of making a employee.cfc, employeeDAO.cfc, employeeGateway.cfc, and employee.as to interface with your employee database table, you're doing the right thing in Flex! But this leaves you with a ton of gateway CFCs, which will be a ton of RemoteObject tags in your mxml. So make a GenericGateway.cfc and only have Flex talk to that. Within this, make a function called employee_getAll, with the same return type as the getAll() function in your employeeGateway.cfc. As you need them, add more functions that call the corresponding functions in employeeGateway. Now you have a single RemoteObject tag, calling functions like employee_getAll, department_save, etc, very clear what it's affecting.

Bundled Flex requests

I have a Flex app that does a bunch of remoting calls to ColdFusion for data to populate some graphs. Even though the RemoteObject tags are in different components and get called separately by sequential lines of code, I noticed that they all returned at the same time, though I know some of them should have returned a lot faster. According to Service Capture, Flex 3 combines all the remoting calls into a single bundle. This makes me curious how Flex decides to combine the calls into a single bundle and more importantly, how do I tell Flex to NOT add a remoting call to a bundle.

Next game idea: Dungeonmancer

The other day at work, I was messing with drag and drop in Flex for the first time and was surprised at how easy it is. As always, my mind starting thinking "how can I make a game out of this?" And the answer was obvious: Make a dungeon!! I played Dungeon Maker: Hunting Ground for PSP a LOT. Way too long, far past when the game is interesting and fun and deep into the terrain of "this game sucks, but how does it end?"

[More]

Flex selectDatagrid()

"omg, murloc, it's a post that's not about video games!"

Problem: You programmically are selecting an item from a datagrid.

Solution: The function below! Pass the datagrid, column you're matching, and the value to match on.

private function selectDatagrid(dg:DataGrid, column:String, value:String):void{
   if( value == null )
      return;
   
   for( var i:int=0; i<dg.dataProvider.length; i++ ){
      if( value == String(dg.dataProvider[i][column]) ){
         dg.selectedIndex = i;
         dg.verticalScrollPosition = i;
         break;
      }
   }
}

Flex selectCombobox()

Problem: You programmically are selecting an item from a combobox.

Solution: The function below! Pass the combobox, column you're matching, and the value to match on.

private function selectCombobox(cb:ComboBox, column:String, value:String):void{
   if( value == null )
      return;
   
   for( var i:int=0; i<cb.dataProvider.length; i++ ){
      if( value == String(cb.dataProvider[i][column]) ){
         cb.selectedIndex = i;
         break;
      }
   }
}

Flex + Report Builder tutorial

A while ago, I posted about jumping through some hoops to get a Report Builder report from a filter page in Flex. I never posted code and it seems no one else ever did out there, though this is becoming a common pattern. So here we go.

You've got a report done in Report Builder (a cfr). Congrats for not killing yourself in frustration over the tool, though I'm sure you thought about it. It generates a nice PDF or whatever, now you want to invoke it from your Flex front end. The Flex front end gives a list of departments, leaders, and job types and you can select any number of each to narrow down what's on your report. How do you get your filter responses to the cfr?

[More]

Beta 2, mixed impressions

So after a day of using Flex Builder 3, beta 2, I'm loving 90% of the changes. But the other 10% makes me want to punch a baby.

First the 10%. Click "Debug", your project compiles and opens fine. Click "Run", your project compiles, opens, and wants the Flash debugger location. Adobe says "working as intended". Says Peter Flynn, "This is intentional. To create a final, non-debug SWF, use "Export Release Version" (available on the toolbar and the Project menu). You can avoid the "Where's the debugger?" dialog box by installing the latest Flash player that is included in the Flex Builder installer." Hurrah for giving the developers more steps to do! Right now I'm messing with deep linking, I don't want to run in debug mode, I want to keep changing the url and make sure my app reacts to it.

Anchors! In design mode, click any component and you'll get little blue bubbles that make constraining the item more visually intuitive. This replacing what they had in the right side "Flex Properties" dock under layout. They've also reordered things, moving Layout to be the second item, which makes more sense, you ("you"="I") use that more than style.

They've also fixed a bug switching to design mode. Before, when you opened a component and changed to design mode, you'd only see the top-right 200x300 or so of the component. With no "design area" option, I'd have to resize the component and undo the change to get the whole thing to show.

And deep linking! I've been drooling over this example for a while, but those files they're importing haven't existed. Now they do.

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner