Adobe Flex 2.0 training day 4

FLEX 2.0Today we started with a whole new part. Now we focussed on data and communication with Flex 2.0. And this all began with accessing a webservice.  When we use a HTTP request then we are able to load data to one page. With a webservice we can talk to one or more methods and retrieve multiple sets of data. When we use the webservice mxml tag (and give id and WSDL file link) we are able to make all the webservice methods, local accesible methods. We there multiple methods we also needs more lastResult properties to capture all the specific data. But that is not a problem because we can use the “webservice id>.<methodname>.lastResult” property. So consuming a webservice is reall really simple in Flex 2.0 ! But when we have multiple methods, each method wants his own eventhandler, so that is the moment that the operation mxml tag comes in. It is a subtag from the Webservice MXML tag. You can specify an eventHandler for every method you have; this is also true for the faultEvents that are dispatched. If you not specify a specific eventHandler (even result or fault handler) then the default eventHandler will be used.

The next unit for today was about the Flex Data Services. This part of Flex is also free but only to deploy one application on a server with one CPU (and yes dual core is also 1 CPU ).For the rest everything is based on the free Flex framework. If you work with the free Flex SDK you can use the command line compiler called “MXMLC.exe“.

If you work with the Flex data services your project must be a flex data services based project. You must set the file system and a path to the webserver. (for server side compilation) When using local compilation the developer decide when to compile, when you use server side compilation the application is compiled when the user looks to page. Actually Flex data services decides on server side if the application needs to be recompiled. When you use FDS you can do several extra things:

  • FDS with J2EE
  • remote object services (you can link clientside value objects to server side objects and there is automatic data translation)
  • flex messaging format (basis of FDS; uses a RTMP protocol = same protocol as Media Server uses to push data from server to clients)
  • flex data management service (FDS takes care of record locking, really splits backend from frontend )


Then we implemented FDS with a java backend using remote object services. The system to let it communicate with a coldfusion backend, PHP,… is the same so when you know the way how to do it is always the same. It uses AMF as protocol. AMF is a binary protocol:

  • more secure then clear text (only 0 and 1)
  • data packages are 1/6th of the size of text ==> less bandwidth  ==> faster protocol
  • still runs on HTTP (or HTTPS)  (no exotic things to do)
  • Flash player also has automatic translation

When you configure a remote object you have to set the destination and that happens in the services configuration file. To let this point to the java backend classes the destination points to a server side adapter and channel.

Next part today was looking to validating and formatting data in Flex 2.0.
There are several validators predefined in Flex. From a CreditCardValidator to a SocialSecurityValidator,… You can create a validator  by using an MXML component or just using Actionscript in the same way as when using other components. You just have to set the source and the property. If the value is required, set the required property to true. You can offcourse also trigger validation with events. You can also set manually the errorString (that will be used then as errormessage when validating).

Regular expressions are also a possibility when using  validating. And you know there are peoples who likes it and peoples who do not like it (and hardly use it) ; I am I guess one of the last group. But if you like it you can use in Flex the regExpValidator control and have fun.

To format data there are also several posibilities in Flex 2.0. On of them is the currencyFormatter. It is really easy to use this control and very handy.

If you want to manipulate complex data in Flex 2.0 you can do three things:

  • filter a data set using a function
  • sort a data set
  • traverse through data set with a cursor (like in MS Access records; next, previous, last, …record)

Here the collection class comes in.  It contains a group of objects and has a set of methods you can use to sort , filter, … .You can define a filterfunction by setting the filterFunction property of an ArrayCollection. So basically the filterFunction decides if a a value must be in the set of data or not, it returns true or false and how it decides it up to the developer who write the specific filterfunction. Then you use the refresh method to actually do the filtering.

For sorting data you first create a Sort object and assign the fields property of the sort object  to an array of SortField objects. Next use the sort property of the ArrayCollection and to actually sort use the refresh method of. Really a complex way to do some sorting, but a very effective way.

At least you can also  use the IViewCursor interface to traverse throuh an ArrayCollection. The cursor always points to a particular item in the ArrayCollection. By using the createCursor() method you can create the cursor on the ArrayCollection.

To end this post, maybe a quick gadget tip Simon mentioned today during the break: It is called PLEO and it is really really cool !! It will be available around Christmas (HINT 🙂 ). You can see a video about the product here.


2 responses to “Adobe Flex 2.0 training day 4

  1. PradeepKumar 6 March , 2008 at 12:05 am

    Nice, Useful for recollection… 😉

  2. PradeepKumar 6 March , 2008 at 12:06 am

    I’ve seen about server side compilation, need more details in that…

    Thx in advance…
    PradeepKumar, D

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s