Today 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:
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:
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:
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: http://www.ayobe.com 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.