Flex Bootcamp at AJAXWorld 2007

This Sunday we ‘ve spent teaching a very intensive workshop on using Flex. This bootcamp was part of the AJAXWorld 2007 in New York that officially starts tomorrow.

This is how it went ndash; every attendee came with his/her laptop with preinstalled Eclipse, FlexBuilder, Java SDK, Tomcat, MySQL Server database. We “ve emailed them instructions on how to do this, but came earlier ready to help with installation/configuration issues, but no help was needed. I spent the first four hours running a hands-on introduction to Flex. And people were running my example applications on their machines ndash; no problem. Data Binding, Custom Events, RSS read using HTTPService, communication with a server-side Java application using RemoteObject. All was covered in just four hours! I asked people if they wanted me to slow down ndash; not at all. It was a really good crowd.

After lunch Victor went through the intricacies of the server side development database applications with Flex. Many of his samples were geared toward pointing people at potential issues of configuration of distributed applications that include Flex, Java and SQL. Then he gave to the students our free library of components that we “ve developer at Farata Systems and demo ‘d a new DaoFlex Eclipse plugin that makes creation of Flex-Java-DBMS applications a breeze. We “ll spend the next three days at the Ajax show ndash; you can find us by the table with our RIA book. We “ll be also showing a number of Eclipse plugins that turn Flex into a Rapid Application Development tool. Stop by if interested.

As to the bootcamp, we “ll be offering it now more often to jump-stat development of the Flex Java enterprise projects. We “ll be offering two versions of this bootcamp ndash; one or two days based on flex-maturity level of development teams.

Hope to see you at the Ajax show.

Yakov Fain

Where professional Flex developers live?

I came up with an interesting way of figuring out where professional Flex developers live without trying to break into secret underground Adobe vaults where classified sales info is stored. Here ‘s the deal, but first, I ‘d like to stress the word PROFESSIONAL here, which means people who use or are planning to use Flex for the real-world project development. Here ‘s my logic – our book RIA Development with Adobe Flex and Java has been printed and the publisher ships it all over the world. As of today, this is the only advanced book on programming enterprise applications with Flex, and this book is not cheap even for American programmers. This technically means that if someone purchases this book, s/he ‘d better be damn serious about programming with Flex.

I ‘ve asked the publisher (Sys-Con Media) to send me statistics (not the abs numbers but percentages) of the book paid orders by country, and these are the numbers:

Country Orders

UNITED STATES 61.26%

SPAIN 5.11%

AUSTRALIA 3.00%

ENGLAND 3.00%

ITALY 3.00%

GERMANY 2.40%

CANADA 1.80%

AUSTRIA 1.50%

NETHERLANDS 1.20%

RUSSIA 1.20%

SOUTH KOREA 1.20%

SWEDEN 1.20%

BRAZIL 0.90%

DENMARK 0.90%

INDIA 0.90%

SAUDI ARABIA 0.90%

SOUTH AFRICA 0.90%

THAILAND 0.90%

BELGIUM 0.60%

ISRAEL 0.60%

JAPAN 0.60%

SWITZERLAND 0.60%

VENEZUELA 0.60%

ARGENTINA 0.30%

CHINA 0.30%

COLOMBIA 0.30%

CROATIA 0.30%

FINLAND 0.30%

FRANCE 0.30%

HONG KONG 0.30%

MEXICO 0.30%

NEW ZEALAND 0.30%

PHILIPPINES 0.30%

Pretty interesting picture, isn ‘t it? No surprises that the most of the orders came from the USA (these filthy rich Americans). But I was pleasantly surprise by the fact that

Spain came second. Wow!

Italy is the fifth! Good job Marco Cassario!

Small Netherland is kicking Flex asses!

Russia made it to the first ten! Yes, spending money on computer books is OK. Good Job Michael Klishin!

What surprises me is that India, Denmark, Brasil, Saudi Arabia, South Africa, and Thailand purchased the same number of books.

What do you think of this statistics?

Immersing into Flex, Java, AJAX, and Microsoft

I ‘ll spend the second half of March ’07 teaching and learning about all these different but related technologies. After finishing an SOA project, my brain needs a good massage, and I consider all these conferences and training sessions as a luxury SPA. Here ‘s my plan (If you want to make God laugh, tell him your plans).

1. March 18. I ‘m running with my partner n intensive one-day Flex Bootcamp as a part of the AJAXWorld conference. It ‘s going to be an absolute hands-on class (everyone must bring their laptops), and we ‘ll create two working applications during this session: a fancy RSS reader in Flex, and a working Flex-Java-DBMS distributed CRUD application. In my opinion, this is a very good injection for anyone who ‘s planning to jump-start a real world Flex/Java project.

2 . March 19-21. AJAXWorld 2007 Conference and Expo, which has a number of world class speakers and I ‘ll turn from an instructor into a student. Meeting with so many smart technologists in the same place at the same time is a great way to learn. During this conference I ‘ll be also participating in our book signing event and will be available for any conversations. Our company is one of the sponsors of this conference, so look for a large sign Farata Systems and stop by for a chat.

3. March 21, 7PM. I ‘ll be presenting at Princeton Java Users Group on creating rich Internet Applications with Flex and Java. This is a free event, please come over, if interested.

4. March 26-28. I was invited to attend Microsoft Technology Summit – it should be an interesting event, where I ‘ll become a learner again. Microsoft has invited a small group of technologists to visit Redmond and meet with people who create Microsoft tools. As far as I understand, they have invited people from non-Microsoft camps, and I ‘m going there as Java programmer.

That ‘s all for March. In April, get back to regular a consulting/training/mentoring work – I need to pay my bills, you know. If anyone is interested in learning Flex attending evening sessions over five weeks, enroll in my class at New York University that starts on April 12.

Once again on outsourcing

Every time I read an article about outsourcing, I can ‘t stop myself from writing yet another blog or an article on the subject. I know that these blogs may not change the big picture, but at least they may draw some attention of selected CIO or CTO. So I “ll keep stirring the outsourcing pot.

Information Week Magazine published an article “Outsourcing to Win: 4 steps to An Effective Strategy rdquo;.

They write, “Campbell says most companies lack the necessary management structure to effectively manage a team of outsourcers. With businesses spreading work around to more and more external contractors, they need to elevate vendor management to the executive level and hire the equivalent of a chief sourcing officer, she says. “There are not a lot of individuals within a company that have the multidisciplinary skills required for that sort of role. ” This is probably the only useful advise that the article gives ndash; the rest is a typical gibberish of standard phrases taken out of the real world context.

Liaz Campbell hit the nail on the head. In my opinion, the lack of management is one of the two MOST IMPORTANT things make the outsourcing fail (I “ll mention the second one a bit later). Of course the roots of this lack of proper management issue lay in the fact that in many cases the project manager has no say in WHO is their outsourcing partners. They are given from above and have roots in the golf courses and fancy restaurants.

OK, the project with outsourcing begins, the project managers quickly understand that the low Bangalore hourly rates is a joke, given the fact that because of the typical corporate infrastructure issues (here in the USA), an offshore team of five $20p/h spent two weeks doing nothing but exchanging emails trying to get access to the proper servers. Let “s do the math: 5*$20*8*10 = $8000. These money just evaporated from the project budget during these two weeks of doing nothing.

Interestingly enough, the upper management will never know about it because hellip;and here comes the second main reason of why outsourcing is much more costly ndash; CONSPIRACY. Project managers will cover up such losses because they do not want to disappoint their managers ndash; their own yearly reviews and bonuses depend on success of their projects, so they “ll quietly absorb these losses by asking their local team members to work more and tie up loose ends. The local team members have their own reviews too, so they “ll work a bit harder as well. For a more details coverage of this use case read my article “What CIO should know about outsourcing rdquo;.

The article suggests to get familiar with the contract laws and religious adherence to standards. This does not come from the real world.

The next advise of this article is to move team-based outsourcing projects. I think it “s dead wrong. Eighty percent of any team (local or overseas team) do not produce much. My advice is to work with the individuals that your team leaders personally pick. If they do not deliver, cut the cord and take the losses in the early stages of the project. Find someone else. Introduce the competition within the Bangalore firm. Provide PERSONAL incentives for individuals. Today “s Bangalore team is a sand castle. People there can easily quit their jobs is someone would extend them an offer with 2% salary increase.

Make sure that you know each and every person who work for you ndash; do not pay for dead souls .

And if your outsourced project failed, stop blaming Indians ndash; just look at the roots of this failure at home.

You are the only person in the conference

A typical corporate morning…Dial in the bridge line…the pass code… “Your pass code has been accepted. You are the only person in the conference “. And then this music that never changes starts slowly destroying my mood. I mean c ‘mon – it ‘s the iTunes era. Can ‘t someone in these telecom giants come up with a program that would RANDOMLY select a melody from a library? Not just yet. The same melody for over 10 years! Tam-ta-ta-ta-Tam-Tam-Tam! Tam-ta-ta-ta-Tam-Tam-Tam! When someone places you on hold, they have a second melody, which is also the same for years. This elevator music is just killing me – I ‘m losing productivity! And I have only one or two meetings a day.

Now I understand why corporate managers look so depressed. On average, they have ten meetings a day, and each of these poor creatures consumes at least 10 minutes of Tam-ta-ta-ta-Tam-Tam-Tam daily. Nazis were using non-stop loud music for tortures in their concentration camps. They did not know that a quiet Tam-ta-ta-ta-Tam-Tam-Tam could have been more effective.

Do you want your son to be a programmer?

I do. But I had this conversation with my colleague whose is one of the top IT professionals I ‘ve ever met. He does not want his kids to become programmers.

I have two sons and one of them has graduated form a non-programmers college. He ‘s got his BS in Fine Arts and now works as an animator. He draws cartoons for various TV shows. My life would be so much easier if he ‘d chosen the IT career, but… he ‘s a talented kid, and my wife and I decided to let him do what he likes. My younger son is a seven grader, and I would not mind if he ‘d decide to become a programmer.

My colleague ‘s argument was that 10 years from now all programming will be done in India anyway, and there is no reason to send your kid to a CS school. I absolutely do not agree with this. Animation industry does not have these outsourcing issues yet, but my older son had really really tough times finding his first job. His friends who have graduated with CS degrees, did not have any problems finding well paid jobs.

In terms of return on investments, I do not think that there are too many professions that would pay you $50K a year right off a second-tier college. And if you get BS in Computer Science from one of the well known schools, you ‘ll start with $70K or more.

The low cost labor from India will not change the landscape in 10 years. In many cases low cost means low quality, and the real cost of outsourced projects is the best kept secret. Good programmers in India are already demanding higher rates, and this trend will continue.

I won ‘t push my younger son in this direction, but will be happy if he decides to become an IT professional. And what about you? Will you advise you kid to pick a software-related degree?

What Ukrainians think of Americans

I ‘ve received an email titled American As They Are. It contained a link to a Web site from the Ukraine that shows a video with number of improv interviews taken on the streets of American cities sampling stupid answers to simple questions. We also see such videos here in America, often titled American Funniest Videos.

Obviously, there are uneducated Americans, that ‘s for sure. But the comments to this post are more important as they shows that Ukrainian people are happy to see this and believe that this make them superior. These are translations of some of the comments to this video (I ‘m omiting the curses) :

2. I still do not understand why this counrty of Americoses did not fall apart yet.

5. Americoses…way to go…We love you, you are the best !!!

9. Oh man, they are so dumb, that I want to die…but ‘m sure that not all.

10. I am sure you can find the same people in our country, but this syndrom is not as wide spread as there.

15. Much better than Zadornov [ Russian stand-up comedian who hate America]. Fell of the chair. LOL.

26. Yes, American is a nation of retarded people, everyone knows this. I ‘m not sure that there is any other country with so many uneducated people…may be in Africa. Do not worry about their quality of life – they came to this in their own way, and not because of their outstanding brain power. And my answer to those who try to advocate them – you have to make fun of them, which will stop our country from falling into the same hole of illiteracy and short sightness.

But some of the comments were more down to Earth:

13. So what? this does not prevent them from living better than us, smarts

19. Each country has retarded people, even yours

31. WTF, something is not fair in this world – we are so smart and so poor, but these…

36. A country that starts with U…Ukraine!!! But the Berlin wall was really something…No, Americans are not dumb, they just have ketchup and mustard instead of brain!

Not knowing that a triangle has more than one side (btw, how many?), is nothing else but the lack of elementary education, but not knowing what the Berlin Wall is or the names of the countries that start with U, is a result of cultural specifics – an average American is mostly concerned about what ‘s happening inside his/her country. This is obviously not the case in Ukraine, where people pay more attention to what ‘s happening “behind the fence ” than to what ‘s going on in their own backyard.

The Ukraine is a country populated with a large percentage of alcoholiks that is run by a bunch of criminals. Most of the regular people there know that laws are not working and you have to give bribes in every step you make. But the ugly realities of their own lives fade away when they see a video of these “stupid Americans “… I ‘m sure their big brother Russia and some other countries would have the same reaction to this video. There is no doubt in my mind that one can easily shoot a similar video in Ukraine. But do not bother, just make fun of Americans, it ‘s a lot easier than building a better country at home. In many cases people hate someone because they can ‘t become this someone.

Finally, or new book is in flash, I mean in print

A couple of weeks ago I stopped by at our publisher ‘s offices (Sys-Con Media) and they showed me our Flex book with the correct cover, but all pages were blank. Yesterday, I ‘ve got an email from them with the words, “Yakov your book is ready, stop by and pick it up “. The guys from production department are really nice, so they ‘ve attached this video just to show me that the book is really really finally super-duper ready. Check this out (the video file is large though).

The book was officially announced over here, and first will be shipped to hundreds and hundreds of people who pre-ordered the book. BTW, people who will purchase the book online should get the PDF version of the book right away, and will receive the printed version as well.

Sys-Con packages the book with a DVD that in addition to the source code of the book samples includes the video of all presentations from the Flex Seminar that took place last Summer in New York City. This package costs $69 USD. I ‘m sure some people will say, it ‘s still expensive. I have two answers to this, pick the one you like:

1. We (the authors) did not set the price

2. Anatole, Victor and I spent a year (in addition to our regular day jobs) writing this first advanced book on Flex, and I personally believe that it worth every penny.

If you are planning to attend the AJAXWorld in March, the book will be sold cheaper there, plus we ‘ll participate in the book signing event and will run one day hands-on Flex bootcamp one day before the conference. Stop by to say hello, and enjoy the reading!

Yakov Fain

Windows Vista – a grim reminder from the past

My new laptop came with Vista, and this is the only reason I found myself in its early adopters camp. The UI is great, but this error message has reminded me the end of 80th. Older programmers remember that infamous Windows 3.0 message “Unrecoverable Application Error ” or UAE. This error meant “You are screwd, reboot and pray “. We just had to accept this error as a reality of life.

Then, before the release of Windows 95, one of the Microsoft top executives announced that with the new OS you ‘ll never see the UAE again, and programmers around the world started partying. The executive was right, the UAE was gone, because MS replaced the error massage with this GPF (General Protection Fault) dialog.

This one has delivered pretty much the same message, “I have no clue what has happend, and the tech support of this program ‘s vendor won ‘t get any helpful info from you “.

After enjoing Vista ‘s eye candy UI, I ‘ve met the reincarnation of UAE/GPF in this form:

This UAE grandchild (the same as its ansector) does not bear any meaningful information that would help to debug the issue, but it has some advantages – it does not use scary words like Unrecoverable or Fault. On the other hand, it does not gives us a chance to quickly come up with some catchy akronym so programmers could enrich their jargon. For starters, I suggest this: Vista ‘s WTF.

This particular error message was about a third party program called VZAccess Manager, I called the vendor and after escalation to the higher level of tech support, someone has told me which DLL to remove to make thir software work. But how do you like this mesage, “Windows will close the program and notify you if a solution is available “. Just let me tell you, “Do not sit by the phone waiting for their call “. Do not sit by the MS Outlook either.

In the future versions of Windows, Microsoft UI designers should improve this message as follows:

1. Remove this only “Close program ” button.

2. Replace this modal dialog with a nice transparent splash window that pops up on your desktop for a second and then gradually dissolves.

If you have an idea regarding the text of the message, speak up. The mike is open.

Event-Driven Programming in Flex with Custom Events

Event-driven programming model offers an excellent architecture based on loosely-coupled components consuming and throwing events. This simply means that a properly designed component knows how to perform some functionality and notifies the outside world by broadcasting one or more custom events. I need to stress, that such component does not send these events to any other component(s). It just broadcast its “exciting news rdquo; the event dispatcher. If any other component is interested in processing this event, it must register a listener for this event.

Before explaining how to create an event-driven component let “s state how we are going to use them. This is a typical scenario: MyApplication uses Component1 and Component2. Components do not know about each other. Any event-handling component should define this event inside. For example, Component1 dispatches this custom event sending out an instance of the Event object, which may or may not carry some additional component-specific data. MyApplication handles this custom event and if needed, communicates with Component2 with or without feeding it with data based on the results of the first component event.

We “ll create a “shopping cart rdquo; application that will include a main file and two components: the first a large green button, and the second one will be a red TextArea field. These components will be located in two separate directories “controls rdquo; and “cart rdquo; respectively.

To create our first MXML component in Flex Builder, select the “controls rdquo; directory and click on the menus File | New MXML Component. In the popup screen we “ll enter LargeGreenButton as a component name and we “ll pick Button from a dropdown as a base class for our component. Flex Builder will generate the following code:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Button xmlns:mx= “http://www.adobe.com/2006/mxml ” gt;

lt;/mx:Button gt;

Next, we “ll make this button large, green and with rounded corners (just to give it a Web 2.0 look). This component will be dispatching an event named greenClickEvent. When? No rocket science here – when someone clicks on the large and green.

Custom event in MXML are annotated within the Metadata tag in order to be visible to MXML. In the listing below, in the metadata tag [Event] we declare a custom event of generic type flash.events.Event. Since the purpose of this component is to notify the sibling objects that someone has clicked on the button, we “ll define the event handler greenClickEventHandler() that will create and dispatch our custom event.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Button xmlns:mx= “http://www.adobe.com/2006/mxml

width= “104 ” height= “28 ” cornerRadius= “10 ” fillColors= “[#00ff00, #00B000] ”

label= “Add Item ” fontSize= “12 ” click= “greenClickEventHandler() ” gt;

lt;mx:Metadata gt;

[Event(name= “addItemEvent “, type= “flash.events.Event “)]

lt;/mx:Metadata gt;

lt;mx:Script gt;

lt;![CDATA[

private function greenClickEventHandler():void{

trace( “Ouch! I got clicked! Let me tell this to the world. “);

dispatchEvent(new Event( “addItemEvent “, true));// bubble to parent

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Button gt;

Listing 1. LargeGreenButton.mxml

Please note, that the LargeGreenButton component has no idea of who will process its addItemEvent. It “s none of its business: loose coupling in action!

In dynamic languages following naming conventions. Common practice while creating custom components is to add the suffix “Event rdquo; to each of the custom events you declare, and the suffix rdquo;Handler rdquo; to each of the event handler function.

Here “s the application that will use the LargeGreenButton component:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Application xmlns:mx= “http://www.adobe.com/2006/mxml

xmlns:ctrl= “controls.* ” layout= “absolute ” gt;

lt;ctrl:LargeGreenButton addItemEvent= “greenButtonHandler(event) “/ gt;

lt;mx:Script gt;

lt;![CDATA[

private function greenButtonHandler(event:Event):void{

trace( “Someone clicked on the Large Green Button! “);

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Application gt;

Listing 2. EventApplication.mxml

We have defined an extra namespace “ctrl rdquo; here to make the content of “controls rdquo; directory visible to this application. Run this application in the debug mode, and it “ll display the window below. When you click on the green button it will output on the console the following:

Ouch! I got clicked! Let me tell this to the world.

GreenApplication:Someone clicked on the Large Green Button.

While adding attributes to lt;ctrl:LargeGreenButton gt;, please note that code hints work, and Flex Builder properly displays the greenClickEvent in the list of available events of new custom component button.

Figure 1. The output of GreenApplication.xmxl

Our next component will be called BlindShoppingCart. This time we “ll create a component in the “cart rdquo; directory based on the TextArea.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:TextArea xmlns:mx= “http://www.adobe.com/2006/mxml

backgroundColor= “#ff0000 ” creationComplete= “init() ” gt;

lt;mx:Script gt;

lt;![CDATA[

private function init():void{

parent.addEventListener( “addItemEvent “,addItemToCartEventHandler);

}

private function addItemToCartEventHandler(event:Event){

this.text+= “Yes! Someone has put some item inside me, but I do not know what it is. \n “;

}

]] gt;

lt;/mx:Script gt;

lt;/mx:TextArea gt;

Listing 3. BlindShoppingCart.mxml

Please note, that the BlindShoppingCart component does not expose to the outside world any public properties or methods. It “s a black box. The only way for other components to add something to the cart is by dispatching the addItemEvent event. The next question is how to map this event to the function that will process it. When someone will instantiate the BlindShoppingCart, Flash Player will dispatch the creationComplete event on the component, our code calls the private method init(), which adds an event listener mapping the addItemEvent to the function addItemToCartEventHandler. This function just appends the text “Yes! Someone has put hellip; rdquo; to its red TextArea.

The application RedAndGreenApplication uses that uses these two components LargeGreenButton and BlindShoppingCart.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Application xmlns:mx= “http://www.adobe.com/2006/mxml ” layout= “vertical ”

xmlns:ctrl= “controls.* ” xmlns:cart= “cart.* ” gt;

lt;ctrl:LargeGreenButton addItemEvent= “greenButtonHandler(event) “/ gt;

lt;cart:BlindShoppingCart width= “350 ” height= “150 ” fontSize= “14 “/ gt;

lt;mx:Script gt;

lt;![CDATA[

private function greenButtonHandler(event:Event):void{

trace( “Someone clicked on the Large Green Button! “);

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Application gt;

Listing 4. RedAndGreenApplicatoin.mxml

Let “s go through the sequence of its events:

When the green button is clicked, the greenButtonHandler is called and it creates and dispatches the addItemEvent event on itself. The event bubbles to the parent container(s) notifying all listening parties of the event. BlindShoppingCart listens for such event and responds with adding text. Run this application, click on the button, and the window should look as follows:

Figure 2. The output of RedAndGreenApplication.mxml

And one more time: the green button component shoots the event to the outside world without knowing anything about it. That is very different from the case when we would write “glue rdquo; code like cart.addEventListener( “click rdquo;, applicationResponseMethodDoingSomethingInsideTheCart).

Sending Data Using Custom Events

To make our blind shopping cart more useful, we need to be able not only to fire a custom event, but this event should deliver description of the item that was passed to shopping cart. To do this, we “ll need to create a custom event class with an attribute that will store application-specific data.

This class has to extend flash.events.Event, override its method clone to support event bubbling, and call the constructor of the super class passing the type of the event as a parameter. The ActionScript class below defines a property itemDescription that will store the application-specific data.

package cart {

import flash.events.Event;

public class ItemAddedEvent extends Event {

var itemDescription:String; //an item to be added to the cart

public static const ITEMADDEDEVENT:String = “ItemAddedEvent “;

public function ItemAddedEvent(description:String )

{

super(ITEMADDEDEVENT,true, true); //bubble by default

itemDescription=description;

}

override public function clone():Event{

return new ItemAddedEvent(itemDescription); // bubbling support inside

}

}

}

Listing 5. The custom event ItemAddedEvent

The new version of the shopping cart component is called ShoppingCart, and its event handler extracts the itemDescription from the received event and adds it to the text area.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:TextArea xmlns:mx= “http://www.adobe.com/2006/mxml

backgroundColor= “#ff0000 ” creationComplete= “init() ” gt;

lt;mx:Script gt;

lt;![CDATA[

private function init():void{

parent.addEventListener(ItemAddedEvent.ITEMADDEDEVENT,addItemToCartEventHandler);

}

private function addItemToCartEventHandler(event:ItemAddedEvent){

text+= “Yes! Someone has put ” + event.itemDescription + “\n “;

}

]] gt;

lt;/mx:Script gt;

lt;/mx:TextArea gt;

Listing 6. ShoppingCart.mxml

There is a design pattern called Inversion of Control or Dependency Injection, which means that an object does not ask other objects for required values, but rather assumes that someone will provide the required values from outside. This is also known as a Hollywood principle: rdquo;Don “t call me, I “ll call you rdquo;. Our ShoppingCart does exactly this ndash; it waits until some unknown object will trigger event it listens to that will carry item description. Our component knows what to do with it, i.e. display in the red text area, validate against the inventory, send it over to the shipping department, and so on.

Next, we will completely rework our LargeGreenButton class into NewItem component – to include a label and a text field to enter some item description, andthe same old green button:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:HBox xmlns:mx= “http://www.adobe.com/2006/mxml ” gt;

lt;mx:Metadata gt;

[Event(name= “addItemEvent “, type= “flash.events.Event “)]

lt;/mx:Metadata gt;

lt;mx:Label text= “Item name: “/ gt;

lt;mx:TextInput id= “enteredItem ” width= “300 “/ gt;

lt;mx:Button

width= “104 ” height= “28 ” cornerRadius= “10 ” fillColors= “[#00ff00, #00B000] ”

label= “Add Item ” fontSize= “12 ” click= “greenClickEventHandler() “/ gt;

lt;mx:Script gt;

lt;![CDATA[

import cart.ItemAddedEvent;

private function greenClickEventHandler():void{

trace( “Ouch! I got clicked! Let me tell this to the world. “);

dispatchEvent(new ItemAddedEvent(enteredItem.text));

}

]] gt;

lt;/mx:Script gt;

lt;/mx:HBox gt;

When we look at our new application with new ShoppingCart and NewItem components, it is almost indistinguishable from the original one. If we would of kept the old class names, we could of used the old application.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Application xmlns:mx= “http://www.adobe.com/2006/mxml ” layout= “vertical ”

xmlns:ctrl= “controls.* ” xmlns:cart= “cart.* ” gt;

lt;ctrl:NewItem / gt;

lt;cart:ShoppingCart width= “350 ” height= “150 ” fontSize= “14 “/ gt;

lt;/mx:Application gt;

Listing 7. RedAndGreenApplication2.mxml

When the user enters the item description and clicks the green one, the application creates a new instance of the ItemAddedEvent, passing the entered item to its constructor, and the ShoppingCart properly properly displays selected rdquo;New Item to Add rdquo; on the red carpet.

Figure 3. The output of the RedAndGreenApplication.mxml

Making components loosely bound simplifies development and distribution but comes at higher cost during testing/maintenance times. Depending on delivery timeline, size and lifespan of your application you would have to make a choice between loosely coupled or strongly typed components. One last note. The itemDescription in Listing 2 does not have access level qualifier. It “s so called package level protection. The ShoppingCart can access itemDescription directly, but the classes outside of “cart rdquo; package can “t.

Event-driven programming is nothing new – we routinely did it in mid-nineties in such toos as PowerBuilder or Visual Basic. In Java, it also exists as an implementation of Observer/Observable pattern. But entire Flex programming is built on events, which makes coding a lot simplier.