Tuesday, December 16, 2008

Few points on Blogging

Today's scenario:

Bloggers are affecting the election
newspapers,radio,tv are loosing their advertising revenues
2005 is known as the year when print journalism began to die
Blogging is new media journalism
podcasting is new media radio
video blogging is new media tv
all this is new media marketing

3 biggest problems of today
1. How to put the websites
2. how do i get the traffic(viewers)
3. building a list who trust you and love you.
It all depends on building the relationships

Why do you want audio and video blog
word press: it is a blogging platform
WordPress is a state-of-the-art semantic personal publishing platform with a focus on aesthetics, web standards, and usability. What a mouthful.
WordPress is both free and priceless at the same time.

Old media is very expensive compared to the internet media

Blog?
Web pages that instantly communicate, educate,sell,announce and have dialogue to the world in text, audio or video.

You become findable. other people can put your references and you become more popular.
The s/w is free
People can  instantly receive your updates by RSS
RSS can get you the content from where ever you want
You can put the audio content on i pod

Apple TV and Tivo can play your podcast and Videos in your subscriber's living room (http://www.apple.com/appletv/)

There are number of rss reader
1.Google
2.yahoo
3.feed reader

itunes has 1 click rss subscription for the podcast and video cast

the old media is a interrupting advertising. They are showing the ads which no body wants to see.
They are broadcasting spam. during cricket match who wants to know about fair and lovely ad

TV advertisers are now turning to online ads

What is new media marketing?
it is a conversational marketing rather than the interrupting marketing
like ad sense, rss based news
New marketing works on the viral behavior i.e. the word of mouth

podcast:audio blog There are software available for preparing an audio blog. sony has one

you should be able to make three types of content:mp3,flv,mp4
through the www.blogmediauploader.com you can upload your audio/video on to your blog
your setting should be 22.5-56k mp3


Tuesday, October 14, 2008

YahooMap Api for Flex 3 is Buggy

I have been using Yahoomap API for quite sometime. There are some annoying bugs which gave me a tough time.
Some of the bugs related to the marker manager are:

1. _yahooMap.markerManager.markers.splice(1,1);
    does nothing. Even though the markers is an array and  should allow the Splice operation to go through but nothing happens

2. _yahooMap.markerManager.removeAllMarkers()
    gives an annoying error.""Error# 1009: Cannot access a property or method of a null object reference"


3. _yahooMap.markerManager.removeMarker(obj as Marker) is also buggy.
 The intended behavior its that it should just remove the particular marker that is passed in the call, instead it removes all the markers that are present after the specified marker. So assuming if the markers array is [1,2,3,4] where the numbers are the marker ids. The call _yahooMap.markerManager.removeMarker(2) will give [1] instead of [1,3,4]


4. _yahooMap.markerManager.pop(): doesnot remove the element from the markers array it just gives the reference to it. So even after the pop() operation the marker manager will contain the recent most marker.

Solution for removing the markers from the marker manager
I have used the a work around for removing the items from the marker manager. I exploited the current behavior(buggy one see point 3) of _yahooMap.markerManager.removeMarker(obj as Marker).

The function is removing all the elements that are present after the marker passed in the call. So I am passing the recent most marker so that it removes latest marker and the markers after that (which will be null). Let me give one example
say the marker manager contains markers #: 1,2,3,4
we will use the following code to remove the markers. so after every pass we get
pass 1: 1,2,3 (4 is removed and there was nothing after that so only 4)
pass 2: 1,2   

pass 3: 1
pass 4: null


    private function removeYahooMarkers():void
        {
            var len:int=_yahooMap.markerManager.markers.length;
            for(var i:int=0;i<len;i++)
                {
                var obj:Object= _yahooMap.markerManager.markers.pop();
           
                if(obj!=null)
                _yahooMap.markerManager.removeMarker(obj as Marker)
                if(obj==null)
                return;
                }
           
        }




Even the overlayManager is buggy.
There is some refresh problem. In case of removing any overlay, the overlay manager does not refreshes the overlays array.
So if you do
_yahooMap.overlayManager.removeAllOverlays(); it would have removed the overlays internally but the overlays array still contains the references (something like dangling pointers in C/C++)
one workaround is to just call the removeAllOverlays(0 again so
            _yahooMap.overlayManager.removeAllOverlays();
       _yahooMap.overlayManager.removeAllOverlays();

Monday, September 15, 2008

Notes on Web 2.0: Part1
Web 2.0 is one of the most popular buzzword around. Lot of people have written about it, lot of books are available in the market. I have tried to compile the variety of information available and give a multi-dimensional overview of the Web2.0.
This is a very easy to understand discussion and should be helpful to everybody who is interested in knowing more about Web 2.0. I will be providing lot of examples to support the information. The article might look like collection of disconnected information, I have deliberately done this because my aim is to act like a collector for information on the web 2.0 from various sources and dump it….A kind of aggregator
The article will help readers to get a starting point and a breadth of information about Web 2.0. Since there are too many things to cover I thought it to be a nice idea to divide the article into parts. Part 1 is a general overview of the Web 2.0 philosophy. In Part 2 I will be discussing about the business impact of Web. Like every Web 2.0 discussion starts with Tim Oreilly’s Web2.0 Diagram, I will also follow the tradition.

  • So what is it?

In simple terms web 2.0 is a set of patterns seen in today’s online sites and businesses that has radically changed the way the web used to be.Web 2.0 is a read and write web, meaning instead of users just reading the information presented to them, they are also allowed to modify the content of the site.

Rather than calling a website we call it a web application in Web 2.0 scenario. This is because earlier the content that was available on the web was just static pages, but now there is a wide variety of content available: web sites, web services, mashups, RSS, Social Networking sites, Video sharing , photo sharing. When we say that it is a Web 2.0 application, it means that we can find some of the design principles of the web 2.0 in the application which have been defined by Tim O’Reilly while coining the term (http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html ): . Since they are the design principles, they are just the guidelines on which your application should be based:

  1. The Long Tail: It is the first indication of User Centric approach. It means that the applications should be more targeted towards the masses than the niche. If a site is for very specific user set than the popularity will be just among those users, but if the site is for the common masses millions of users will be using it. YouTube( http://www.youtube.com ) , Flickr (http://www.flickr.com ) are all the followers of this philosophy. The site is open to masses. We will see later that long tail is the reason why Web 2.0 businesses have grown from 0 to billions in a span of 2 years
  2. Data is the Next Intel Inside: Just like the core part of the system is the processor, similarly the core part of the web application is the data that it is providing. People go to Flickr because Flickr has got one of the largest searchable database of Photos. YouTube sits on millions of Videos that users can search for, and view them. Data has become the identity of the web business. We will discuss this in length in the next part of this article
  3. User Add value: This I would say is the core of Web 2.0. If the application has does not allow the user to add some kind of meta data or the content, then it is not a Web 2.0 application. I have discussed it in length in the later part of the article
  4. Network Effects by Default: The value of application increases with the growing number of users. Fax would have been useless if there were not many users ready to send and receive the fax. The value of the product is not what the product is but how many people are ready to use it. The users will come to a social networking site because they find their friends on the site (orkut, facebook), users visit ebay because they find buyers for their products. If tomorrow the buyers stop coming to ebay, the sellers will also stop. People are ready to write applications on facebook because they think that their friends are going to use it and appreciate them. So Web 2.0 applications grow because of the user base and their constant engagement with the site. In order to understand it more please refer to http://en.wikipedia.org/wiki/Network_effect , http://web2.socialcomputingmagazine.com/hackingwebnetworkeffect.htm, Also “Web 2.0: A Strategy Guide: Business thinking and strategies behind successful Web 2.0 implementations” by Amy Shuen (http://www.amazon.com/Web-2-0-strategies-successful-implementations/dp/0596529961/ref=bxgy_cc_b_text_b) will be invaluable to understand some of the business implications of network effects.
  5. Some Rights Reserved: Normally people have Intellectual property rights which prevents users from modifying the content or using them in other places. Since Web 2.0 is all about people and their collaboration, strict licensing cannot be productive. The Applications are designed to encourage people to contribute…In words of Tim O’Reilly the Design for Hackability and Remixability
  6. The Perpetual Beta: Web 2.0 has introduced a new kind of development model called Perpetual Beta. The applications will be launched and called as Beta versions. This is because they are continuously being improved by following the users feedback. Some of the applications are building daily more than once. Flickr went from many iterations from what it was when Yahoo! Bought it to what it is now.Applications need no hard media to distribute since its all web based so the deployment means just loading the executable on the web server.
  7. Software above the level of a single device: Applications have to talk to various other applications to come up with a good use. Design the applications to integrate the services across handheld devices, PCs, web applications.
  8. Cooperate, Don’t Control: No Body is the boss. The stories published on Digg (http://www.digg.com ) are what readers want to read and not what NewYork times want the readers to read. Wikipedia (http://www.wikipedia.org ) is a collaborative effort of millions of people towards building up a encyclopedia. Nobody contols Wikipedia. Web 2.0 applications give their user the resources to utilize in what ever manner they want. This has been reflected in growth of numerous businesses: YouTube, Flickr, facebook (http://www.facebook.com ), Amazon (http://www.amazon.com ) and list goes on.


A good web 2.0 application will have the 3 main features

  1. Good content, data: Data is what attracts the users. People come to Flickr because of the large database of photos, Amazon provides a rich database of the books and so on. The data is essentially easy to search.
  2. Social Architecture: Enable the users to interact and work collectively. For e.g. the users can view the photos of other users, they can write scraps, they can create their profile, express themselves on blogs, they can connect to different people http://www.websocialarchitecture.com/community/2007/03/the_basics_of_w.html gives a detail overview of what is social architecture is all about.
  3. Architecture of participation: Users can add content to the existing applications. Flickr allows them to upload photos, Youtube videos, wikipedia allows the user to add new wiki page and so on

In short the Web2.0 can be defined as:
Content+commerce+community+context+personalization+

intelligent search=Web 2.0


Web 2.0 is all about the buzz words and jargons. The following are some of them




We can categorize these buzzwords into few categories:
Technology:

  1. AJAX
  2. RSS
  3. ATOM
  4. RIA
  5. SOAP
  6. REST
  7. CSS
  8. XML/XHTML
  9. Ruby on Rails
  10. Open APIs

User Collaboration/Social Aspect

  1. Participation
  2. Trust
  3. Accessibility
  4. Remixability
  5. Folksonomy
  6. Ranking
  7. Social Networks
  8. Communities
  9. Forums
  10. Viral Feedback Loop


Content creation

  1. Wikis
  2. Blogs
  3. Comments
  4. Recommendations
  5. Reviews


User Experience

  1. Joy of Use
  2. Simplicity
  3. Interactive media

Even though we say that Web2.0 is a read/write web but the number of users who really add the contents are very few.
We can divide the users into 3 categories
  • Users who create the content
  • Users who add the meta data information, so they add value to the existing content
  • Users who are just reading the content: more of a web 1.0 behavior but majority of the users is like this

Trust plays an important role in Web 2.0 applications.

  • Wikipedia allows the users to add the wiki pages on the various topics. Nobody is controlling the information, it is all about the trust that the users will not enter wrong and objectionable stuff.
  • ebay whole business model is based on trust. It facilitates the buyers and sellers to reach to a deal. Both the parties are unknown but still engage themselves in business
  • Social networking sites allow the users to add their personal information. The personal information plays an important role in connecting the people. Trust is the main factor why people are ready to enter their personal information and supporting the model of social networking sites

Web 2.0 applications are known for providing rich user experience: AJAX is almost necessary component for building the applications. AJAX provides the dynamic updates of the page without actually refreshing the entire page.The web sites will generally have components like maps, RSS feeds, videos, dynamically updating controls, glassy icons.


Sites are pushing information to the user. This is one of the major change from the earlier web sites and the current websites. Early websites (web1.0) required users to regularly visit the site to check if some new updates have been done. This is not a very clever solution since the probability of user doing this is very low except for the few websites. Suppose I am a fan of Linux journal , I might take the pain of visiting the site everyday to check if some new article has been published. But another user who is not that crazy about Linux might not take pain to visit the site regularly. In this manner the site is loosing on its users. Web 2.0 has a very well documented notification mechanism RSS which is all about updating the users about any changes on the site. So with RSS I don’t have to go to Linux Journal site. Instead I will just subscribe to the RSS feed from the site which keeps updating with any updates on the site. So I get the notification once the site is updated and so I can then visit the site.


Tagging/Folksnomy: Tagging helps users to categorize their content on the web. Delicious is based on tagging. The users bookmark the links by categorizing them with a tag. This helps in easy searching of the bookmarks later. Flickr allows the user to categorize their photos by giving meaningful tags. They can later search the photos based on the tags. Tagging has got lot of meta information which is quite valuable. Refer to my blog posting for the benefits of tagging


Web as platform: Web 2.0 is laying the foundation on which users can build the applications. It is providing the basic components/modules that are required to build applications. A typical application will require a Database, some APIs or libraries, messaging system to communicate between different components, UI, some kind of computation that is the brain of the application. Normally a person will use the Database from some vendor, APIs from other vendor, use a programming language for writing logic and bind them together. He will use some Hardware to run the application. So basically the different modules or technologies for creating an application are used from different vendors and assembled to get the final product.

The same concept is supported by the various applications of the Web 2.0. We have different type of modules that can be used to create new applications
1. Storage Services(equivalent to data storage in desktop applications): Amazon S3
2. Compute Service: Amazon EC2 which provide a computing facility. You can run your application on Amazon’s hardware
3. Information Services: A rich set of APIs providing specialized data. Like Google map, Flickr, Twitter, Delicious, Amazon, ebay
4. Messaging Service : They are like middleware concept passing the messages from one application to another. Amazon Simple Queue Service is one such example.
5. Various technologies like AJAX, RIA, SOAP, REST, CSS, XML, Ruby on Rails, Grail and so on

I have earlier posted the platform concept in depth on my blog which I would suggest will help a lot. Tim O’Reilly has discussed it in length in his classic Web 2.0 discussion.


Remixing and Mashups: Mashup means blend distinct data from 2 or more sources/APIs together to add more value to what was already there. E.g There are map APIs from Google which allows you to get the map based on Latitudes/Longitudes. They can be blended with a News data so that clicking on any place on the map will give the News related to that area. Now this is a blending of two data to produce something that is more valuable.They are one of the most popular reasons for the disruptive growth of web. Google Maps, Flickr, YouTube, Amazon provides APIs through which users create a new application making use of the data from these sites. For e.g. User might use the Google Map APIs to create a real estate agent site. User might love to see photographs of any place in the world. He can combine Google Maps and Flickr APIs to do so.
Apart from the fun part, mashups do have lot of business value in them. Real estate business has benefited with the sites where they can get the real time property rates and the geographic maps for the site so that the clients can see the property before buying it.

Web 2.0 applications generally display the 3 dimensions
  1. Technical: The Applications are created using some of the most advanced
    languages/software. SOAP, REST, RSS, AJAX, Ruby on Rails, GWT etc. The
    whole mashup thing has taken the SOAP and REST to new heights. (They
    are the new versions of SOA).
  2. Users Centric: User Centric aspect I have discussed a lot and will be revisiting later
  3. Business: Web 2.0 applications are running into big busisnesses. Youtube, facebook, mySpace made billions in a short span of time. We will be looking into the business aspect of Web 2.0 in the next part of the Notes.

The Web 2.0 is not only for the techie guys who are deep into coding and stuff. A web 2.0 application can be built by or owned by a completely non technical person. It takes just 5 minutes to start your blog site and start blogging ( check www.blogspot.com ). Any person can use Google Ads to start getting the Ads on the site. Google provides a very easy way to start you own portal (iGoogle). Even if there is a need for programming, it is very simple and most of the times the sample code is available, the user just has to make some minute changes to get it working.The most popular APIs are the ones which are easy to use. This is because the APIs are being used by a diversity of people (from techie to non techie).


Today almost every type of application is available on the web:
a. Videos/Audios sharing: YouTube

b. Photo Sharing: Flickr

c. Social Networking: Facebook, Orkut, MySpace

d. Books: Amazon

e. Storage: Amazon S3

f. Computing Facility: Amazon EC2

g. Trading: ebay,PayPal

h. Bookmarking: Delicious

i. Maps: Google,Yahoo!

j. Office Applications (word, excel): Google Docs, Zoho

k. Project Management: Zoho

l. Encyclopedia: Wikipedia

m. Messaging: Twitter, skype

And the list goes on. It is not too far when you need not install anything on the system, all software including OS will be web based. You will just require a very scale down version of say Linux to get the browser running and Web 2.0 will take it from there


Let me spend some time on how users have contributed in making the applications better.

  1. Wikipedia is the best example of user content that has helped in creating one of the largest encyclopedia.
  2. The search results on Google are very much dependent on how many users have referenced the links, popularity of the page, any meta information associated
  3. Flickr allows users to tag the photos. This has helped Flickr to improve their search results drastically
  4. YouTube is all about sharing the Videos. Users create the video and share it..Broadcast Yourself.
  5. Facebook is allowing the users to build up new applications and host them on facebook…as expected it is one of the latest craze among the facebook users
  6. Digg is all about users adding their votes to make the news to show up on the main page or not
  7. Amazon Product Reviews is one of the major ways how people get to know which is the better product. The users search keywords and shopping history help Amazon to find out the shopping tendency of users, so that they can “suggest” what is bought along a particular product. So you bought a book on Design Patterns by Gang of Four and there comes a Amazon suggestion saying those who bought this book also bought “Refactoring by Martin Fowler” All this is user added meta data that is helping Amazon to serve its user better
  8. Delicious tags are added by the users. They have a great value in making the links searchable. Find out more about the tagging from my posts http://rohitagarwal24.blogspot.com/2008/02/use-of-collaborative-tagging-in.html and http://rohitagarwal24.blogspot.com/2008/01/how-to-add-tag-cloud-to-your-blog-tag.html


This should give an overview of Web 2.0. I think I have touched base on all the key aspects of the philosophy. I will cover the business impact of web 2.0 in great details in the next part of the article. In case you want me to explain some portion of the article in more details kindly leave a comment.You can follow me on delicious for web 2.0 related links.


Tuesday, September 9, 2008


Why We buy ?


I had never thought upon this until I got this book in my hand.



The information given in the book is based on practical studies conducted in different retail shops, departmental stores. Data gathered has been analyzed thoroughly and findings put in the book. The stuff is kind of hillarious and mind boggling. While you are reading the book you will take some time to think ..Is Paco talking about me?
Paco for instance, discusses the implication of the trolley/baskets on the shopping experience, what happens if your shelves are oriented at an angle of 45 versus 90, what is the sales boost in having a merchandise displayed at the entry of the store versus in some middle section, A kid coming with his/her father is a better customer versus when he/she coming with mother and so on.
Paco has touched base on very common things which can significantly change the shopping and sales.
Buy Book at Amazon





Add to Technorati Favorites

Monday, September 8, 2008

Download: A History of the Internet on Discovery Channel

A cool new series is being telecasted on Discovery channel. This is the great way in understanding the Internet revolution that happened in the last decade and which has changed our lives for ever. The Series will let us know some of the key events that took place, the key companies/products that changed the digital world and the people behind them. I am really excited for this.
More information on the same is available at
http://www.hastac.org/node/1251
I also found a google video http://video.google.com/videoplay?docid=380058528391483877

Some of the key points from the Video:
  1. Internet is about connecting people
  2. Youtube: Broadcast yourself. There is not central control of the video--No master of the media
  3. DIGG: People digg (vote) the story so that its get featured on the main page. People are deciding what they consider exciting and what not
  4. facebook: Its all about relationship among human beings. facebook is trying to map the way man thinks he is connected to the other people..concept of social graph.
  5. facebook allows you to develop applications and host them on facebook so that others can see and use them.
  6. General pattern of the popular web 2.0 businesses is :
    1. started in college dorms as a fun project
    2. launched among college students
    3. through word of mouth gets vastly popular
    4. geek opts to drop out of the college
    5. starts a company based on the project
    6. A giant business buys it at an incredible rate
    7. college geek becomes extremely rich ......time involved for hitting this jackpot ~2years
  7. Some of the key acquisitions were Youtube by google (1.65bn$), MySpace by Rupert Murdoch(600million $), facebook by Microsoft,flickr by Yahoo, delicious by yahoo
  8. Digital media specially music has played a big role in bringing the people together
  9. It was because of the mp3 that the music could be compressed and easily shared on the net
  10. Napster laid the foundation of the new experience on the internet i.e. exchange digital media. Today Youtube allows you to share the video, flickr allows to share the photos but back in 98-99, Napster made the sharing of music a child's play and took the internet by storm
  11. Napster was the fastest spreading software at that time.
  12. The USP of Napster was if there is a computer on the internet which has got collection of songs and you want to download those songs...establish a peer to peer network with that computer and get the songs. Napster software helped in doing that. No computer is the central repository. Your home system can be a repository for somebody sitting in some part of the world
  13. Because of Napster people from different geographic locations , who had never heard about the other, no mails, no chat were suddenly exchanging massive data...This also laid the foundation of social networking
  14. An estimate says that 85% of the total bandwidth available in the college networks was being used to exchange music
  15. The internet usage suddenly raised and so the number of users... The user centric application theme got the first voice through Napster
  16. The popularity of Napster had raised the questions of copyright violation of the digital media which overnight became available for free. The record stores lost major market since the college guys (their major customer) were downloading the music for free.
  17. Unfortunately Napster company was shutdown after the court order..but it had showed the would be Youtube, flickr, digg how to get the people attention. Majority of internet users are not worried about the information about latest books, articles, conference,how stuff works. instead they want to play with media. They want to watch movies, videos, photos, listen to free music, communicate with friends. Its all about what are the most common interests of people and can you provide them over the internet..Bang you have a new rocking web business
  18. MySpace is another business that boosted the Social Networking idea in the sillicon valley and suddenly we had facebook, orkut coming up on those lines
  19. Youtube, MySpace, facebook have earned their founders a lot but there are some businesses which are as popular as these businesses but they are not earning any money: Craiglist, wikipedia
  20. The philosophy of craiglist is that they want to provide the newspaper classified sections for free. The advertisements are more organized , easy to search and available for almost all geographic loactions in the world. I can search for all advertisements for a house in NY,USA sitting in Bangalore,India.
  21. Youtube provide people to share videos , Flickr provided photo sharing, Digg provided people the ability to decide what they consider is the top news, facebook provided people opportunity to make friends and remain connected to them....now people would also like to become authors,publishers and what not, so we have BLOGS
  22. Blogging is one of the most popular activity on the internet. People blog on various things. People feel excited that they can also write contents, and publish them just like any author in OLD days used to do. If you are reading this article then you know what I mean :)
  23. There is a whole lot of potential to become a new business on the internet...just need to find if it is user centric,how can a user participate in changing the content of your site. Today the User wants to become a peer in adding the content on your site rather than just a meek recipient of the content.



Add to Technorati Favorites

Saturday, September 6, 2008

Brand Value: Silverlight versus Flex

How many people have heard of Microsoft? May be everybody who has a PC
How many people have heard of Adobe? I bet a very small fraction of the above population.
When Microsoft comes out with a product the user base is already there looking for that product. They launched Vista last year but people were already waiting for it since last 3-4 years.
This is the power of branding. Microsoft has clearly established in that perspective. Whether their offerings are really that cool or not is the other part of the story.
Microsoft, historically has bee bit passive in the internet technologies. The Browser wars(Netscape versus IE) is a classic example. WEB 2.0 is the current buzz word in the Internet parley and it is taking the world with storm. The companies are coming up with RIA (Rich internet applications) which offer very rich UIs, almost like the Desktop. Its all about user experience. The applications are marketed for their rich experience rather than their functionalities.
Anyways coming to the M-Aspect, Adobe (they actually coined the term RIA) came up with their Toolkit called Flex, to make the development of RIA easy and fast. Flex has been around for about 3 years and has become quite stable technology. A lot of people around the world have embraced this technology and are developing really cool web applications. Lot of big names in the market like Yahoo, HP, SAP are using Flex for their products. But even with so much support the common people have never heard of Flex or RIA.
2 years back Microsoft started working on Silverlight as their offering against Flex. Even though it is not being used in any commercial web sites but people are excited about it. If you discuss people about flex, the first question will be why don't you use Silverlight....Its from Microsoft. Even though they have neither worked on Silverlight nor on Flex, but they feel more comfortable to put their bet on Silverlight compared to Flex.
In my opinion this is all because of the Brand Value. People have a kind of faith in the brand they have been using. Microsoft has always been looked upon as a company which comes out with new programming languages, Operating systems, Office software...practically everything. So its obvious that they have come up with a RIA toolkit (Siverlight).
On the other hand Adobe, is known for software like PDF reader, Writer, PhotoShop...none of them is a OS or a general programming language. So when Adobe comes up with a language and a new paradigm of developing internet applications, people have doubts on their credibility. Another blow to the Flex popularity is the fact that it doesnot use javascript. Currently the general notion about the internet applications is: A website with javascript, XML, AJAX, CSS, RSS and so on. Now Flex uses actionscript which again raises people eye brows. Lot of javascript vs actionscript debate started in the recent years. Whenever such debate start, its likely that the people who are the supporters of one technology will start promoting it with full support. They will write blogs, give usage statistics etc. So now a person who is new to both actionscript and javascript when tries to decide upon which way to go, he follows an easy metrics of the popularity.
Silverlight is based on javascript so thats another advantage.
AJAX is another technology or I will say paradigm that has to be there in case your website has to get any respect. Flex never advertise much on the AJAXian capabilities. They advertise RIA more than AJAX. Web 2.0 is all about the jargons and clearly jargon AJAX is lot more popular and than RIA. Web 2.0 is associated with AJAX. I have heard lot of early Web 2.0 heros admitting that without AJAX there is no Web 2.0. So when you have a product whose sole USP is RIA, a new person who wants to have a web 2.0 type of website immediately raises doubt: If I use flex will my website be called Web 2.0?
Just to summarize Flex is a great product and is very easy to use, but from the popularity wise it will face tough competitions. One of the major factor that helped flex to reach upto the current state was the fact that was an early entrant. But with so many companies and specially Microsoft offering the same type of product, its going to be tough time for flex.




Add to Technorati Favorites

Sunday, August 24, 2008

Kingfisher Flying with Linux

KingFisher Airlines, Indias most colorful and luxurious domestic airlines provides Entertainment system which are based on Linux.
It so happened that I was travelling from Hyderabad to Bangalore in KingFisher flight. 5 min before the take off , all the entertainment units got restarted. I was totally amazed when I saw a Linux boot sequence getting displayed on the screens. It was an embedded Linux ( a scale down and customized Linux especially for the Embedded Systems). After the booting was over the X window console came and then suddenly the moving map. The entire thing was very exciting. I wanted to share this information at that time itself. I sent SMSes to my friend who is a Linux Junnkie. I wanted to send this information to everybody who can get excited like me. For the first time I realized the use of microblogs like twitter. Had I got a twitter account on mobile I could have immediately posted the information on my twitter widget on the Blog. So the flight seem to be providing me lot of insights....
For all the Linux junkies KingFisher is a nice example of proving the use of it in the commercial systems.





Add to Technorati Favorites

Saturday, August 2, 2008

Easiest way to crack an Interview

Cracking an interview is what most of the people look forward. People generally prepare a lot for an interview in terms of their technical stuff, personal questions etc. All this is fine but I think even the interviewer is aware of all these preparations the candidate usually do, so he might not be very impressed if you answer him in the artificially imposed sophisticated looks and manners. The interviewer has 1 min to judge you and you have to take the lead in that 1 min. I have recently given 4-5 interviews (just for fun) and in all those interviews I found that no body is actually interested in looking at you "artificial manners". They will be more than happy if you remain what you actually are. So here is the trick and this is applicable for both freshers and the experienced people.
Just to put it in simple sentences
1. Prepare slides or some visual depiction of the work you have done so far.
2. Ask the interviewer permission to show your stuff.
3. In all probability he will say yes
4. Using your slides/ graphs give an overview of the work
5. Be very casual while describing. The words should be just oozing out of the mouth.
6. You should look proud and confident of what you have done. Think as if you are selling your work to a customer
7. You should tell what impact you work has put in the current company (if you are switching the job) or if you are fresher than how your work has been judged by the college
8. All this has a great effect on the interviewer.
  • He thinks that you are confident about what you have done--so you are not telling a lie.
  • He thinks that you are sound in the area that you are looking for.
  • He understands that you can express yourself---a very important quality
  • He understands that you can sell your case ---If you cannot market a thing then what is the use to produce it?
  • He thinks that you are professional-- slides, graphs, if permitted a prototype
9. If you have impressed the interviewer by your presentation, then it really don't leave any space for rejection, since Interviewer gets answers to all the potential questions.

In Short
"BE COOL AND TALK RATHER THAN LISTEN AND GET TENSE"

My take on REST and SOAP

  1. Soap supports more RPC style of architecture where the use of SOAP is to invoke a remote function carrying in the message the function name and the various parameters. The RPC is basically a function that is sitting on a remote machine.
  2. The function has a specified number of parameters that needs to be provided to make use of the function. The use of SOAP is to make requests to such functions and to get the response back.
  3. SOAP uses XML to transfer the data and so it is heavy in size.
  4. The SOAP message is cryptic in the sense that it contains a header that wil specify the route, the info about the message and sometimes the security aspect for the message
  5. The SOAP message is difficult to create without the tools. So these days the langusgaes provide the library functions which will create the SOAP message
  6. The SOAP is generally sent using HTTP but other protocols are also valid like Java Message service
  7. SOAP is very function (verb ) centric. The way you get the things done is by calling a function so to get the stock prices you will call a function (web method: A webservice will have number of methods) getstock(GE)

Now the function will calculate the price and send it back to you

You must know the names of the function and the way it is going to use the parameters. For that you need to get the WSDL file which is very cryptic.

  1. SOAP syntax is not user friendly and human readable
  2. When SOAP makes the http request its difficult to find out which http method it is actually going to use.

REST

In case of rest the functions are fixed it will be get, put, post and delete. You will mention the name of the stock directly while making the request (each object will have a different URI) so www.stockprice/category/stock/GE

In this case the description of how to make the call is very simple and its intuitive.

No extra tool is required, The call is very simple.

REST is only for http since it uses the protocols methods GET, PUT(Update), POST (create), DELETE. This is good since the user don’t have to find out which method will be used for a specific purpose. Its basically service_name/noun so Stock is a service and GE is the noun

Tuesday, May 13, 2008

Password validator in flex 3


create a validator PwdValidator.as

package valueObjects

{
import mx.validators.ValidationResult;
import mx.validators.Validator;

public class PwdValidator extends Validator {

// Define Array for the return value of doValidation().
private var results:Array;
// this will help in getting the status
public static var VALID:Boolean = true;


// Constructor.
public function PwdValidator() {
// Call base class constructor.
super();


}

// Define the doValidation() method.
override protected function doValidation(value:Object):Array {
//var pwd: Password = value as Password;
var p1: String = value.first;
var p2: String = value.second;

results = [];
results = super.doValidation(value);


if(p1 == p2)
{
VALID=true;
return results;
}
else
{
results.push(new ValidationResult(true, null, "Mismatch",
"Password Dosen't match Retype!"));
VALID=false;
return results;
}
}
}

}


Now the flex code should be passing the value of the password and confirm password textbox. This is done as

<mx:Model id ="pass">
<name>
<passwords>

<first>{txtPassword.text}</first>
<second>{txtConfirmPassword.text}</second>

</passwords>
</name>
</mx:Model>

// this is the way to pass the multiple controls input to the validator.
<val:PwdValidator id="custPass" source="{pass}" property="passwords" listener="{txtPassword}"/>

<mx:Form labelWidth="110">

<mx:FormItem required="true" label="Password">
<mx:TextInput id="txtPassword" displayAsPassword="true" />
</mx:FormItem>
<mx:FormItem required="true" label="Confirm Password">
<mx:TextInput id="txtConfirmPassword" displayAsPassword="true" change="custPass.validate()"/>
</mx:FormItem>

</mx:Form>


Wednesday, May 7, 2008

Five best bollywood lines

1. Border : If every soldier leaves the battlefield to serve his family, who is going to fight the enemy
2. RHTM.. never say i dont eat nonveg, say I have not eaten it since long time
3. DDLJ: Whats there in Zurich , real europe is countryside.
You can not spend the entire life with your friends, you got to have a beloved
4. Zameen: In our country its illegal to kill stray dogs
5. OSO: Every story has a happy ending, if you think the end is not happy it means the story is incomplete

Saturday, May 3, 2008

New Book on Web 2.0



A must read book. The author has explained the Web 2.0 philosophy in a very intuitive way. He talks about how to monetize the websites at the same time attract the users by giving them
some free services. He calls this as Freemium.
The book discusses the success stories of Flickr, Facebook,Linkedin, google. The basis of all the success story is the rich user base.All of them have followed the long trail concept by reaching out to the masses rather than concentrating to a niche segment " Every buck counts".
Since the book talks about the sites which we commonly use it is easy to realize the concepts since we are the part of the revolution happening around the particular site.

I would highly recommend this book to anybody who wants to find out what is this web 2.0 business all about.

Saturday, April 19, 2008

How to create XMLListCollection from XML in flex 3

There are times when the data that you obtain is in the form of XML or a string that contains XML tags. For displaying the data in datagrid, list, trees we desire to convert the data in the XMLListCollection. We need to perform the following steps to get the XMLListCollection.

1. Lets assume that we want to convert the following string to the XMLListCollection

var xmlStr:String="<root>
<person>
<name>Rohit</name>
<surname>Agarwal</surname>
<phone>5551234</phone>
<age>24</age>
</person>
<person>
<name>Richa</name>
<surname>Mittal</surname>
<phone>5552341</phone>
<age>23</age>
</person>
<person>
<name>Puneet</name>
<surname>Jain</surname>
<phone>5553412</phone>
<age>23</age>
</person>
</root>";

2. Convert the string to XML

private var pat:XML ;

pat=new XML(xmlstr);

3. Convert the XML to XMLList. We want to have individual persons as seperate XML objects

private var patList:XMLList;
patList = pat.person;

4. Convert the XMLList to XMLListCollection

[Bindable]
private var patListCol:XMLListCollection;
patListCol = new XMLListCollection(patList);

In this way the XMLListCollection is created from the XML





How to convert a XML to ArrayCollection in Flex

I wanted to use AdvancedDataGrid control of Flex 3, for which the best way to represent data is in the form of an ArrayCollection. The problem was that the data available to me was in the form of an string(XML serialized as string) and not objects. So I wanted to convert the XML to ArrayCollection.

Steps
1. The following is the string that I wanted to convert:

var xmlStr:String="<root>
<person>
<name>Rohit</name>
<surname>Agarwal</surname>
<phone>5551234</phone>
<age>24</age>
</person>
<person>
<name>Richa</name>
<surname>Mittal</surname>
<phone>5552341</phone>
<age>23</age>
</person>
<person>
<name>Puneet</name>
<surname>Jain</surname>
<phone>5553412</phone>
<age>23</age>
</person>
</root>";

2. Convert the string to XMLDocument

var xmlDoc:XMLDocument = new XMLDocument(xmlStr);


3. Convert the XMLDocument to object by using SimpleXMLDecoder

var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
var resultObj:Object = decoder.decodeXML(xmlDoc);

4. Declare an ArrayCollection
[Bindable]
private var patArrayListCollection:ArrayCollection = new ArrayCollection();

5. Add the resultobj to the ArrayCollection

patArrayListCollection.addItem(resultObj.root.person);

The important thing to note here is the composition of the patArrayListCollection is in the form
[0] --main object
[0]-sub object 1
[1]-subobject 2
[2]-subobject 3

This is not in a form that we require to make it a data provider for the AdvancedDataGrid. The Grid requires the ArrayCollection to have
objects in the form
[0]-object 1
[1]-object 2
[2]-object 3


So to get this form the following step is done

6. var tempArray:ArrayCollection=patArrayListCollection.getItemAt(0)as ArrayCollection;

7. Finally assign tempArray to the AdvancedDataGrid
myADG.dataProvider=tempArray;






Sunday, April 13, 2008

ActionScript Error #2148:
SecurityError: Error #2148: SWF file file:///C:/Documents and Settings/UserProfile/Desktop/flexstore/bin-release/flexstore.swf cannot access local resource myFile.swf. Only local-with-filesystem and trusted local SWF files may access local resources.


This runtime error is thrown in Flex 3 if some where in the application you are trying to do a httpservice and use a resource from the local folder.
<mx:HTTPService id="fillTreeByCatRPC" url="categories.xml" resultFormat="e4x" />

I have seen this error only in Flex 3, Flex 2 never gave this error.

I did some google and found some solutions. Almost all the solutions suggests that one should change the flex compiler settings.

"add these arguments to the compiler (via Properties - Flex Compiler) : -use-network=false " http://curtismorley.com/2007/08/31/flash-cs3-flex-2-as3-error-2148/#comment-3714

The problem with this solution is that once the settings are changed then the application will not be able to read any remote resource. so the below request will fail
<mx:HTTPService id="fillTreeByCatRPC" url="http://www.resources.com/categories.xml" resultFormat="e4x" />

After doing further searches on Internet, I found that it is the setting problems of the flash player that cause the problem. Basically one needs to set the security settings of the flash player so that it allows the swf file to access the resources on the local system. This is done by visiting the following page
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

Make sure that the Global security settings are set to Always Allow

The following screenshot is what we are looking for
Once the settings has been done, Restart the browser and Flex 3 IDE

In all probability the error is gone.


Sunday, March 9, 2008

Customized event in Flex 2

Events are a way of sharing data between two components. Events also acts as a asynchronous message suggesting that some input has arrived to the receiver of the event. For e.g. when a person clicks on the button control the event click is generated signifying that a user input in the form of a click has occurred. Once the event has occurred we need to take some action like on button click display the “hello world” in a text box. The action that we take is known as handling of the event. Or in other words we need to specify the even handler. Event handler is a function that specifies what needs to be done on that particular event.

The following code snippet makes it clear

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx=="http://www.adobe.com/2006/mxml"

layout="vertical">

<mx:Script>

<![CDATA[

//Event handler for the button click function

private function buttonEventHandler(evt:Event):void{

taTest.text="Hello World";

}

]]>

</mx:Script>

<mx:Button id="btTest" label="Click Me" click="buttonEventHandler(event)" />

<mx:TextArea id="taTest" />

</mx:Application>


buttonEventHandler is the event handler that will be called when the button is clicked. One salient point to note is the argument passed in the handler. We pass the object of type Event i.e event. The object “event” is always available in the application and we need to use it at the time of calling an event handler.

Sometimes it happens that we need to transfer some data between the two components.

For e.g. there may be a component which is responsible to get the data from the server using a httprequestserver. Component populates the data in a collection and now wants to send to another component which implements the list or data grid to display the information to the end user. The events are the way through which this can be done. The catch here is that the event thrown by one component should be available in the other component. So the component1 when it is done with populating the collection will throw an event indicating which needs to be handled in the component2 responsible to display the collection in the datagrid. It happens because of the way the events are transmitted from the component to the Application. Before getting into the transmission concept we need to understand one more concept known as event listener. Event Listener signifies that the component wants to receive a particular event and so it wants to register itself as one of the recipients.

We use the function addEventListener(event name , event handler) to do that. Now you must be wondering that the above button code did not had any such function call then how were we able to handle the event. The simple answer is that the event that we talked about was provided by the flex framework and so every component has got an implicit event listener for such events.

But the events that we are now going to see are the one that user has created himself (customized events). The customized events are used to transfer the data. These are created by the users and so the components will not be aware of them. Event Listener explicitly registers the component to listen to these customized events.

HOW TO WRITE A CUSTOMIZED EVENT

There are 3 stages in order t use a customized event

1. Create customized event

2. Dispatch the customized event

3. Listen the customized event.

Create Stage

Let us see how we actually write a customized event. We are just discussing the salient points here which are required to write a customized event. Syntactical and theoretical details are well covered in the Adobe documents.

Customized event can be declared by writing a class that inherits from Event.

package controls

{

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);

itemDescription=description;

}

override public function clone():Event{

return new ItemAddedEvent(itemDescription);

}

}

}

These are the steps that need to follow for defining any customized event

1. The class has to extend Event

2. Declare what ever data type you want to transfer by this event.

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

3. One can give a name to the event for easy reference. In our case it is ITEMADDEDEVENT. We can give multiple names to the same event. This is required when we want to use the same event in different places. For e.g. in a shopping cart application we need to perform add item to cart, delete item from the cart and update the quantity of the item in the cart. In all the operations the same item type data is required to be passed. So we can define a single customized class that favors for the transfer of a item type data. But the same event class can be used for all the 3 functions. We will give 3 names so that we remember for what all purpose we are calling this class.

public static const ADD:String = "addtocart";

public static const REMOVE:String = "removefromcart";

public static const UPDATE:String = "updatecart";

4. In the Constructor we need to call super(). The parameters required to be passed are the type of the event (ADD,REMOVE,UPDATE) and the optional parameters specifying the properties of the event.

Super(type, isbubble,iscancellable)

The second argument signifies whether the event is allowed to bubble. i.e. an event thrown by a component is allowed to be listened by the components that are up in the hierarchy.

5. clone() . This is required as per the Adobe document. We need to override the clone function and in the body just instantiate the customized event and return the object so created.

override public function clone():Event

{

return new ItemAddedEvent(itemDescription);

}

That is all to be done for a creation of an event.

Dispatch stage:

The event is thrown by the component in this stage. There is a well defined procedure to be followed to do that.

Lets take an example and do that

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Metadata>

[Event(name="addItemEvent", type="controls.ItemAddedEvent")]

</mx:Metadata>

<mx:Label text="Item name:"/>

<mx:TextInput id="enteredItem"/>

<mx:Button width="104" height="28" cornerRadius="10" fillColors="[#00ff00, #00B000]" label="Add Item" fontSize="12" click="greenClickEventHandler()"/>

<mx:Script>

<![CDATA[

import controls.ItemAddedEvent;

private function greenClickEventHandler():void{

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

// throws the event and the passes the string to the customized event object

dispatchEvent(new ItemAddedEvent(enteredItem.text)); // passing the string

}

]]>

</mx:Script>

In the example

<mx:Metadata>

[Event(name="addItemEvent", type="controls.ItemAddedEvent")]

</mx:Metadata>

The metadata section is an optional section that tells that these are the events this component is going to dispatch. It is more for giving the information to the developer that this particular code dispatches some event. This is useful since the other components by looking at the metadata section can find out the events they can listen to.

We give the name of the event (addItemEvent) and the location of the class (controls.ItemAddedEvent). Note we could have also given ITEMADDEDEVENT in place of addItemEvent.

private function greenClickEventHandler():void{

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

// throws the event and the passes the string to the customized event object

dispatchEvent(new ItemAddedEvent(enteredItem.text)); // passing the string

}

When the greenClickEventHandler() is getting called on the click event the component is calling the dispatchEvent function. By calling this function the component is actually throwing the customized event. The dispatchEvent function requires the object of the Customized event class as an argument. So essentially we have passed the data structure (in this case string) to the event. This data will be available to all the component who will listen to this event.

Listening

This is the process of registering for the event. The component has to explicitly tell the application that it wants to get the event thrown by the other component and handle the data that is also being passed along with the event. This is done with the help of addEventListener function. The next section will make this concept clearer. For now we can assume that the function allows the component to receive the event and then handle it.

For e.g.

Component called

addEventListener(ItemAddedEvent.ITEMADDEDEVENT,addItemtoCartEventHandler);

to register the event and tell which handler function to call

private function addItemtoCartEventHandler(event:ItemAddedEvent):void{

sample.text+="yes a book has been added"+ event.itemDescription;

}

In the event handler pass an object (event:ItemAddedEvent) of the customized event class type and then use the data passed through the event using the object passed in the argument.(event.itemDescription)

Now the final step is to instantiate the component that will generate the event which is

<controls:newlargebutton />

The way it will work is

Instantiate ----:comp1 will throw the customized event on click----: comp2 will listen to it and call its event handler

Now lets get into the intricacies of how the events are propagated between the components.

In Flex in order to use any component, that component must be instantiated in the application(the application tag).

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

comp 1

comp 2

comp n

</mx:Application>

The Application is the root of all the components. So if make a hierarchy tree it will look like

<Application>

| |

<Comp1> <comp2>

So we can say that Application is the parent node of comp1 and comp2

Again there can be a situation where we instantiate a component inside another component. Like

<hbox>

<list>

<button>

<hbox>

so list and button are getting instantiated in hbox

so in these cases the hierarchy tree will look like

<Application>

|

<comp1>

|

<comp2>

But in this case also <application> is related to comp2 in a ancestral relationship.

We need to understand this point because of the nature of event propagation. When any component generates an event it can be listened by all the components that are higher in the hierarchy. So an event generated by comp2 can be listened by comp1 and the Application. This means comp1 can have an event listener to register for the event generated by comp2, similar is the case with Application.

So if comp2 has to send any data to comp1, it will simply generate an event which will send the data to the comp1 which would be listening for this event.

There may be a situation where the components are not in the direct hierarchy but are in a sibling relation

<Application>

| |

<comp1> <comp2>

Now an event produced by comp2 will be easily listened by Application, but not by the comp1. But comp2 wanted to make comp1 listen to the event. Now events that are listened by the parent can be listened by the children also through following command

parent.addEventListener(event type,event handler)

This means that comp1 can listen to the events that reaches upto the parent. So the event sent by comp2 reaches Appication. Now this event can be heard by the comp1.

So in order to pass the events from one component to another one has to look at the way they are related to each other and depending on that call the addEventListener().

Lets look at some of the examples for understanding the concepts

E.g.1 There are two components related to each other in a parent child relationship. Comp1: It’s a VBOX containing a button and a textbox.

Comp2: A VBOX containing TextArea

Now the requirement is that in comp1 what ever is entered in textbox should be displayed in Comp2 textarea on the button click. So basically we want to send text string from comp1 to comp2. This is a classical situation where we will write a customized event to transfer the string between the two components.

The way we have arranged the components in the implementation is

<Application>

|

<comp2>

|

<comp1>

so addeventlistener will be called without parent prefix in comp1

Custom Event class (ItemAddedEvent.as)

package controls

{

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);

itemDescription=description;

}

override public function clone():Event{

return new ItemAddedEvent(itemDescription);

}

}

}

Comp1 (newlargebutton.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Metadata>

[Event(name="addItemEvent", type="controls.ItemAddedEvent")]

</mx:Metadata>

<mx:Label text="Item name:"/>

<mx:TextInput id="enteredItem"/>

<mx:Button width="104" height="28" cornerRadius="10" fillColors="[#00ff00, #00B000]" label="Add Item" fontSize="12" click="greenClickEventHandler()"/>

<mx:Script>

<![CDATA[

import controls.ItemAddedEvent;

private function greenClickEventHandler():void{

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

// throws the event and the passes the string to the customized event object

dispatchEvent(new ItemAddedEvent(enteredItem.text)); // passing the string

}

]]>

</mx:Script>

</mx:VBox>

Comp2: (BlindShoppingCart.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"

xmlns:controls="controls.*"

creationComplete="init()">

<mx:Script>

<![CDATA[

import flash.events.Event;

import controls.ItemAddedEvent;

private function init():void

{

// eventlistener

addEventListener(ItemAddedEvent.ITEMADDEDEVENT,addItemtoCartEventHandler);

}

private function addItemtoCartEventHandler(event:ItemAddedEvent):void{

sample.text+="yes a book has been added"+ event.itemDescription;

}

]]>

</mx:Script>

<!—instantiated the comp1 -- >

<controls:newlargebutton addItemEvent="addItemtoCartEventHandler(event)" />

<mx:TextArea id="sample" />

</mx:VBox>

Application (greenbutton.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="vertical"

xmlns:ctrl="controls.*" >

<ctrl:BlindShoppingCart width="350" height="200" />

</mx:Application>



Same example but instead of child parent relation change it to sibling

So the instantiation of the comp1 will not happen inside comp2 instead it will happen in the Apllication

<Application>

| |

<comp1> <comp2>

Custom Event class (ItemAddedEvent.as)

package controls

{

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);

itemDescription=description;

}

override public function clone():Event{

return new ItemAddedEvent(itemDescription);

}

}

}

Comp1 (newlargebutton.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Metadata>

[Event(name="addItemEvent", type="controls.ItemAddedEvent")]

</mx:Metadata>

<mx:Label text="Item name:"/>

<mx:TextInput id="enteredItem"/>

<mx:Button width="104" height="28" cornerRadius="10" fillColors="[#00ff00, #00B000]" label="Add Item" fontSize="12"

click="greenClickEventHandler()"/>

<mx:Script>

<![CDATA[

import controls.ItemAddedEvent;

private function greenClickEventHandler():void{

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

// throws the event and the passes the string to the customized event object

dispatchEvent(new ItemAddedEvent(enteredItem.text)); // passing the string

}

]]>

</mx:Script>

</mx:VBox>

Comp2: (BlindShoppingCart.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:controls="controls.*"

creationComplete="init()">

<mx:Script>

<![CDATA[

import flash.events.Event;

import controls.ItemAddedEvent;

private function init():void

{

// eventlistener

//addEventListener(ItemAddedEvent.ITEMADDEDEVENT,addItemtoCartEventHandler); --wont work

parent.addEventListener(ItemAddedEvent.ITEMADDEDEVENT,addItemtoCartEventHandler);

}

private function addItemtoCartEventHandler(event:ItemAddedEvent):void{

sample.text+="yes a book has been added"+ event.itemDescription;

}

]]>

</mx:Script>

<mx:TextArea id="sample" />

</mx:VBox>

Application (greenbutton.mxml)

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="vertical" xmlns:ctrl="controls.*" >

<ctrl:newlargebutton width="350" height="82" />

<ctrl:BlindShoppingCart width="350" />

</mx:Application>

In case the parent.addeventListener is not given , the event is not dispatched to the comp2 and so on button click the text in the text are is not written.



Since in the example we have given parent.addeventListener, so comp1 and interact to comp2 via parent and we get