Programmaticaly sorting a column in an AdvancedDataGrid

ActionScript, Flex, tips 'n tricks No Comments »

Here's a quick tip: If you want to sort a column of an AdvancedDataGrid, without having to set up a sort on the dataprovider, you can dispatch an AdvancedDataGridEvent of type AdvancedDataGridEvent.SORT from the datagrid.

This can be useful if you have a custom sort function on a datagrid column and you want the datagrid to be sorted initially without requiring the user to click the column header.

Actionscript:
  1. var sortEvent:AdvancedDataGridEvent = new AdvancedDataGridEvent(AdvancedDataGridEvent.SORT);
  2. sortEvent.columnIndex = 0; // first column
  3. dataGrid.dispatchEvent(sortEvent);


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Maven, Flex Mojos and Flash Builder 4 tip

Flash Builder, Maven, tips 'n tricks 3 Comments »

Here's a quick tip for those of you who are using Flash Builder 4's FlexUnit integration and also build with Maven and Flex Mojos.

When executing the unit tests of your library project or application, Flash Builder creates a FlexUnitApplication.mxml file in the root package of your main class path. This file is the test runner UI that gets compiled when the tests are run. The problem is that when you try to execute a Maven build on your project, the build will fail because the test runner UI will also get compiled.

A solution is to use the maven-clean-plugin in the build phase and configure it to delete the FlexUnitApplication.mxml file.

To use it, place the following xml in the "build/plugins" section of your Maven build file. You might need to change the "directory" setting to match your classpath.

XML:
  1. <plugin>
  2.     <artifactId>maven-clean-plugin</artifactId>
  3.     <configuration>
  4.         <filesets>
  5.             <fileset>
  6.                 <directory>src/main/actionscript</directory>
  7.                 <includes>
  8.                     <include>FlexUnitApplication.mxml</include>
  9.                 </includes>
  10.             </fileset>
  11.         </filesets>
  12.     </configuration>
  13. </plugin>

If you now execute a "mvn clean install" command, the file will be removed and the build should succeed.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Flex Formatter Eclipse Plug-in

ActionScript, Air, eclipse, Flash Builder, Flex, Flex Builder, tips 'n tricks 11 Comments »

If you're using Eclipse and Flash/Flex Builder, you might want to have a look at the Flex Formatter Plug-in. It's a great add-on that allows you to (auto-)format your ActionScript and MXML files, based on the templates you define.

This is a key feature that is still missing in Flash/Flex Builder in my opinion.

More info: http://sourceforge.net/projects/flexformatter/


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Unable to access UserTransaction in DataService

Flex, Java, tips 'n tricks 13 Comments »

Note: Just a short post to save your hair from turning gray (I know mine just did)

If you ever run into a "Unable to access UserTransaction in DataService" error when working with LCDS on Tomcat 5.5.x+, make sure you configured the Java Open Transaction Manager (JOTM) correctly. You can do this by adding the following in a project config file (META_INF/context.xml or a file named [MY_PROJECT].xml in [TOMCAT_HOME]/conf/Catalina/localhost):

XML:
  1. <Context reloadable="true">
  2.   <Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
  3. </Context>

Now if only the Flex Project Wizard would do this for us...


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Flex 3 Localization

ActionScript, Flex, tips 'n tricks 30 Comments »

With Flex 3 comes the ability to do runtime localization. Compared to Flex 2 where you actually had to recompile your application for each locale, you can now have one version of your application that contains different resource bundles.

Today I implemented this in one of the applications we are working on and ran into some issues. Here is how I got it to work in a nutshell. (Note: for a full instruction on implementing localization in Flex 3, I recommend the article Flex 3 Details - Runtime Localization)

- create a folder in your project to store your resource bundles (e.g. "locale")
- create a subfolder for each locale you want to implement (e.g. "locale\nl_BE" and "locale\fr_BE")
- in the locale subfolder, create a resources.properties file and save it as UTF-8
- enter the resources in the form of "key=value", like Ant property files
- update the compiler settings: -locale=nl_BE,fr_BE -source-path=locale/{locale}

You now also need to create localized framework resources. To do this, take the following steps:

- open a command line (run as administrator in Vista!)
- go to the "bin" folder in your Flex SDK installation folder
- run the copylocale.exe tool for each locale, this will copy the localized framework files from one locale to another (copylocale en_US nl_BE)
- check FLEX_HOME\frameworks\locale to see if the folder for your new locale has been created
- if you get an error "could not find resource bundle charts", search for a file called charts_rb.swc and copy it to the new locale folder in FLEX_HOME\frameworks\locale

A simple example of asking for a localized string:

Actionscript:
  1. // tell the compiler what resourcebundle to use
  2. <mx:Metadata>
  3.   [ResourceBundle("resources")]
  4. </mx:Metadata>
  5.  
  6. // if you are in a subclass of UIComponent
  7. var myString:String = resourceManager.getString("resources", "myKey");
  8.  
  9. // ...or if you are not in a subclass of UIComponent
  10. var myString:String = ResourceManager.getInstance().getString("resources", "myKey");

You can put these calls in a binding expression and switch your locale at runtime by setting the localeChain property on the resourceManager:

Actionscript:
  1. resourceManager.localeChain = ["nl_BE"];

That's about it. Have fun!


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in