Beginning Flex: Creating your first custom event

Filed under: Flex

comments (5) Views: 6,629

Welcome to the first "real" article in my burgeoning "Beginning Flex" series. Today we're going to talk about creating custom events. As you may know, Flex is based on Actionscript 3 an object oriented, event driven, language. What are events you ask? Events are things which trigger actions. Your mouse hovering over this line of text causes the cursor to turn into a little I-bar. Clicking on a button in my navigation fires an event which loads a new page. Flex offers a wide range of events, from mouse triggered events, keyboard events, click events, they're all represented. In many cases the built in events are just what you need.

But sometimes, you want a little something more. You need to send a piece, or a whole packet, of data along with your event. Maybe you just want other developers to know that something special is happening in your code, who knows. The point is that not only does Flex offer those nice built-in events, but it also allows you to create your own. This article will show you how.

Before we get started, let's take a look at the result of the work we're about to do.

picture of directory structure Start by creating a new Flex project, alternately you can download the files for this article as a Flex Builder project and import it. For this one, I've named the project CustomEvents. There's also never a better time to organize your code, so I'll also create an events folder, and a components folder (as you can see to the right). We'll also have the Class file for the event, as well as a single component file containing the Button. I've tried to comment the files thoroughly so that it makes more sense. If you've got questions, please feel free to ask them in the comments. In addition to downloading the Flex project, you can also pull the old "right click to view source" trick on the Flex movie itself.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

Related Posts


comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s