The life and times creating engaging media experiences.

July 2007

» to Main Page
Difference Between "target" and "currentTarget"

When adding an event listener to an object in your ActionScript 3.0 code, it is helpful to understand the difference between the "target" and "currentTarget" objects that can be referenced in the listener function that gets called after the event fires. The object obtained by referencing "target" is the object that dispatched the event. The object obtained by referencing "currentTarget" is the object that is listening for the event. With event bubbling, there can be a difference between the object that dispatched the event and the object that was listening for the event.

Learning ActionScript 3.0

There are several useful resources available from Adobe as you learn ActionScript 3.0. The ActionScript 2.0 Migration guide is particularly helpful for learning the equivalent commands in ActionScript 3.0. The Adobe Development Center also has articles on an ActionScript 3.0 Overview as well as a Tips & Tricks article.

Furthermore, the step-by-step instructions and examples presented in the ActionScript 3.0 Essentials Training video on Lynda.com (subscription required) were instrumental in my coming up to speed with ActionScript 3.0.

Streamline Code Using The Conditional Operator

Instead of writing 5 lines of ActionScript code for a simple if..else block, you can achieve the same logic in 1 line of code using the "?:" conditional operator.

For example, the following piece of code...

     if (x < 5) {
          y = 1;
     } else {
          y = 2;
     }

... can be written in one line as follows...

     y = (x < 5) ? 1 : 2;

More information about the conditionanl operator can be found in the official Adobe documentation.