A Deep Dive into Flash Builder 4
Now, back in Flash Builder, you should see the new operation for the PlayerService in the “Data/Services” panel. If you do not, you probably just need to do a refresh by right-clicking in the panel and selecting the “Refresh” option. Once you see the operation, you might notice that it has a return type of “Object,” while the other operations have concrete return types. So, next we will tell Flash Builder the return type by right-clicking on the operation and selecting the “Configure Return Type” option. Since Flash Builder already knows about Players from our table generation, we will use the “Use an existing data type” option and select “Players”, as seen in Figure 16.
We now have the service configured and need to hook up our players lookup to happen when the user selects a new row in the teams ComboBox. Let’s go back to the Flash Builder design view and click on the ComboBox, which should bring up the configuration in the Properties panel, which is along the right side in the default layout. We are going to select the “Generate Service Call” option for the “On change” event in the panel, as seen in Figure 17.
As you can see in Figure 18, Flash Builder will return a simple dialog to select which service call should be used. We want to use the “getPlayersByTeam” operation on our PlayersService, and click “Ok” to continue.
After finishing with the Generate Service Call dialog, Flash Builder will take you directly into the event handler code. We need to update the service call to pass the team id for the selected item, see Figure 19 for the proper code. This will give us the right list of players whenever the teams drop down is changed by the user.
protected function comboBox_changeHandler(
(event.currentTarget.selectedItem as Teams).id);
Figure 19 Players Service Call Event Handler
Now that we have our event handler setup, our application will load the players for a given team whenever the drop down changes. If you run the application now, you won’t see any changes happen in the user interface, as we have not told the list of players to be displayed anywhere. So, next we want to click on the DataGrid component, and then find the properties panel to do the data binding. We will do this by selecting the “Bind to Data” drop down on the “Data provider” field.After selecting the “Bind to Data” option, the dialog in Figure 21 will be returned. We want to use the “Existing call result” option, as we have already setup the service call to happen whenever the team drop down changes. We will select the “getPlayerByTeamResult,” which was created for us by Flash Builder to hold the results of our service call.
That’s it! We are ready to run the application again. When you do, your running application should look simliar to Figure 22, with the list of players changing anytime you select a different team.
On the server side code generation front, it may not be realistic to generate service side code (with no security) for a production application, but the PHP generation can still serve a purpose. It can offer a nice way to jump start your server-side coding process, or help user interface developers remove the dependency of those working on creating the production services, as they can use this option to begin work without waiting for the final services.
Regardless of the services you are accessing, or how they are created, the new client side data-centric features are a powerful new development option for Flex developers, as it is now quick and easy to add services to a Flex project and bind them to user interface components. While there is not time to do a hands on review of all of the new data-centric features here, hopefully what we covered gives you a sense of the power that has been added in the latest release of Flash Builder.
In this article, we reviewed the latest and greatest features of Flash Builder, and walked through a hands on example of using the tool’s new data-centric features to create a Flex application. From what we have covered, it is clear that Flash Builder 4 is a worthwhile tool for creating Flex applications, with quite a few interesting new features.
Jon Rose is an enterprise software consultant and Flex Practice Director at Gorilla Logic, Inc. (www.gorillalogic.com) located in Boulder, Colorado. He is an editor and contributor to InfoQ.com, an enterprise software community. He is the co-host of DrunkOnSoftware.com, a videocast for those who like booze and bits. He has worked with clients large and small in both the private sector and government. His love of solving problems drives him to build quality software. You can read his blog at: http://gorillajawn.com.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)