DZone and Manning Publications have partnered to bring you an exclusive chapter from 'Flex 3 in Action' (by Tariq Ahmed). This chapter covers ActionScript's core concepts. It discusses comments, variable types, operators, loops, conditions, arrays, and functions.
ActionScript is an extremely powerful object-oriented language about which you can dedicate entire books. In this chapter we’ll focus on ActionScript’s core concepts; obviously you will need to be familiar with them before we get to the more powerful aspects of Flex itself. Speaking of which, you’re probably anxious to get back into Flex, but tackling some ActionScript fundamentals will allow us to pick up the pace and move further forward.
A fundamental concept in any programming language is that of comments, so we’ll begin our discussion with how Flex supports documenting your code.
A basic construct of any programming language is the ability to document the mechanics of an application from within the code itself. You will learn to do this through the use of comments.
From the perspective of implementation, a comment is a sequence of delimited text that is ignored by the Flex compiler. Flex’s ActionScript language supports two popular formats: inline comments with regular code, and block style with multiline comments.
The first comment type is the inline style which you invoke using double-forward slashes:
// one comment
var x:int; // another comment
As you can see, comments can exist on their own line, or inline, alongside code. Using inline comments has limitations; the compiler recognizes the text following doubleforward slashes as a comment only until the end of the current line. A line return signals the end of the comment and the resumption of programmatic code.
If you want to provide a much larger description using free-form text, you can use a multiline comment instead. Begin a multiline comment by typing a forward slash and asterisk (/*), and close it with the inversion (*/):
here is a chunk
Commenting code serves two major purposes: it helps describe how the code works, and it assists in testing and debugging. With respect to documenting the code, it makes sense to use comments not only to be meaningful to other programmers, but to help keep track of what you’ve done for your own benefit. For debugging, you can
temporarily comment out blocks of code to perform testing and diagnostics during the development process.
Let’s move to variables, which allow you to gather and store information.
Comment to get this book FREE!
Post a comment to this thread telling us about your experience with Flex 3, or give us some feedback on this chapter.
The two most insightful comments, as determined by our team, will each be rewarded with a free copy of Flex 3 in Action.
Variables of course, are the basic building block of any programming language. They contain data you use to keep track of information, maintain the state of your application, and enable the user to manage data.
follows a more recent version of ECMAScript).
The above introductory excerpt was taken from Flex 3 in Action, published in January 2009. It is being reproduced here by permission from Manning Publications. Manning early access books and ebooks are sold exclusively through Manning. Visit the book's page for more information.