IdleSun's Weblog

September 30, 2008

Wanna sleep in Flex?

Filed under: Flex — idlesun @ 10:58 pm

There is no sleep or delay function in ActionScript. Like JavaScript, you can use setTimeout() instead like this:

function trigger():void { setTimeout(doIt, 1000); }
function doIt():void    {"done!"); }

Once you link the trigger() function to any event such as ‘click’, when the event happens alert box will show up after 1 sec.

There is also setInterval() and clearlnterval() functions you can use for repetition. However, it is recommended to use flash.utils.Timer class in that case.

Embed a XML file in Flex

Filed under: Flex,XML — idlesun @ 6:40 pm

Although you can embed XML string in the Flex code, you would want to make it as a seperate XML file and use it. So that you can get the benefits of editing XML data using XML editor. One of the easist way I found to embed external XML file is use [Embed] metadata tag. Here is the sample code:

var testXml:Class;

function init(): void {
  var xml:XML = as XML;;

It is really simple, isn’t it? However, this technique has a couple of limitations like:

  • XML file can not have a XML declaration line like “<?xml version=”1.0″ encoding=”utf-8″?>”
  • To use international characters, save XML file in Unicode not in UTF-8

Sample Source: click right button on this link and select “Save Link As” to download the file and rename its extension to “zip”

September 15, 2008

Keep the generated in Flex

Filed under: Flex — idlesun @ 4:56 pm

Everybody who is using Flex (whether with SDK only or Flex Builder) knows MXML files are converted to Action Scripts. But I just wonder how many of us keep the generated code and take looks at them. It is very rare but sometimes you may get an error that is referring to the generated code.

In order to keep the genrated Action Script files use the “-keep” compiler argument, or in Flex Builder add it through the Project Properties dialog like this:

Adding -keep argument in Flex Builder

Adding -keep argument in Flex Builder

With this argument added, you will find the ‘generated’ folders where you have an application or module files. You definitly want to check what AS files are are generated from your MXML files.

Blog at