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://ectropic.com. Jon has posted 3 posts at DZone. View Full User Profile

A Deep Dive into Flash Builder 4

03.15.2010
| 69518 views |
  • submit to reddit


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:IndexChangeEvent ):void
{
getPlayersByTeamResult.token =
playersService.getPlayersByTeam(
(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. 

 

Conclusion

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.


Author Bio

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.

AttachmentSize
Figure1.png25.48 KB
Figure2.png278.1 KB
Figure3.png268.5 KB
Figure4.png123.78 KB
Figure5.png87.18 KB
Figure6.png92.34 KB
Figure7.png22.82 KB
Figure8.png42.73 KB
Figure9.png86.41 KB
Figure10.png75.77 KB
Figure11.png116.61 KB
Figure12.png85.23 KB
Figure13.png46.92 KB
Figure14.png53.57 KB
Figure15.png60.69 KB
Figure16.png71.06 KB
Figure17.png42.95 KB
Figure18.png53.58 KB
Figure19.png52.35 KB
Figure20.png31.61 KB
Published at DZone with permission of its author, Jon Rose.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Harlow Ward replied on Mon, 2010/04/05 - 5:28pm

The one thing that seems to be missing here (and all other Zend AMF tutorials) is how to have objects within objects. I.E. Person has a foreign key to Team. So in the datagrid it would be nice to be able to reference the persons team via {person.team.name}.

 This would also be helpful for the Combobox when picking a persons team in the entry form. This way you could use 'selectedItem' as {person.team} instead of having to loop through the choices and select {person.team_id} when it matches the options.

 Its straight forward with Java, and Hibernate makes it even easier. But i've yet to see anyone do it with PHP yet  OO style.

Dave Keen replied on Sun, 2010/04/11 - 4:07am

Hey Harlow (and all),

Unlike Java and Coldfusion, Flex and PHP have had the short straw for a long time when it comes to data-centric ORM style development.

I have been working on a project called 'Flextrine 2' designed to address this once and for all - a Flex interface onto the upcoming Doctrine 2 library for PHP 5.3+; the project is still under development, but so far it looks extremely promising, and both I and folks I have chatted to about the project think it has the potential to change the face of Flex/PHP data-centric development :)

Please feel free to follow the project at http://code.google.com/p/flextrine2/  I am aiming for a release date of 1st September, to coincide with the stable release of Doctrine 2.

Regards,

Dave Keen
http://www.actionscriptdeveloper.co.uk

Peter Hirt replied on Fri, 2010/11/12 - 2:29am

first, I am learning Flex4, so bare with me. I run the standard tutorial with no problems, but now would like to apply it to my specific case. So, I specifically would like to add more combo boxes and get the results back depending of what I do select with those combo boxes. I seem to have troubles with the inserted PHP code pasted below. I obviously changed the fields to my specific case, but it seems not to work. My questions are: i) variable $teamID is free to choose or linked to somewhere? ii) where can I find documentation of what is exactly interacting with this PHP file many thanks Roestigraben public function getPlayersByTeam($teamID) { $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where team_id=?"); $this->throwExceptionOnError(); mysqli_stmt_bind_param($stmt, 'i', $teamID); $this->throwExceptionOnError(); mysqli_stmt_execute($stmt); $this->throwExceptionOnError(); $rows = array(); mysqli_stmt_bind_result($stmt, $row->id, $row->first_name, $row->last_name, $row->jersey_number, $row->team_id); while (mysqli_stmt_fetch($stmt)) { $rows[] = $row; $row = new stdClass(); mysqli_stmt_bind_result($stmt, $row->id, $row->first_name, $row->last_name, $row->jersey_number, $row->team_id); } mysqli_stmt_free_result($stmt); mysqli_close($this->connection); return $rows; }

Tony Zhao replied on Sat, 2012/06/09 - 3:15am

This would also be helpful for the Combobox when picking a persons team in the entry form. This way you could use 'selectedItem' as {person.team} instead of having to loop through the choices and select {person.team_id} when it matches the options. Its straight forward with Java, and Hibernate makes it even easier. But i've yet to see anyone do it with PHP yet OO style. http://www.china-casting.org

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.