Lyndsey has posted 139 posts at DZone. View Full User Profile

Book Giveaway & Exclusive Chapter Download: Flex 3 in Action

11.16.2009
| 9775 views |
  • submit to reddit

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.

Comments

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.

Inline Comments

The first comment type is the inline style which you invoke using double-forward slashes:

// one comment
var i:int;
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.

Block Comments

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
of text
*/

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

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.

Although variables are common in all languages, their implementation varies from language to language. ActionScript may be a considerable departure from that with which you’re currently familiar. ActionScript is based on a standard called ECMAScript, which is the same standard on which JavaScript is based (though ActionScript
follows a more recent version of ECMAScript).

Click here to download the entire chapter


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.

 

AttachmentSize
Chapter3Flex3iA.pdf287.89 KB
book_flex_3.jpg21.25 KB
Published at DZone with permission of its author, Lyndsey Clevesy.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Josh Marotti replied on Mon, 2009/11/16 - 4:58pm

There isn't many insightful things to say about variables declaration and comments, but seeing as the only real competition with Flex is JavaFX, it is interesting to see that AS is closer related to JavaScript instead of Java.  However, seeing as those interested in Flex are front-end developers who are already familiar with JS, it seems like a smoother transition from ANY backend language (whether it be Java, .NET, PHP, etc...), which really gives Flex more of an audience than JavaFX (and why JavaFX hasn't caught on nearly as well).


Regardless, I've been toying with trying out and playing with Flex, but didn't have the time to go through the movies.  I'm used to the old-school learning of a language, and that is through books, so I hope I'm considered for this book, as I'm highly interested in checking it out!

Stephen Robillard replied on Mon, 2009/11/16 - 9:08pm

I was fortunate enough because of my work in Education to get a copy of flex builder for free. This book would make the perfect accompaniment to me really getting up to speed with flex and building a few advanced adobe air apps I have planned. BTW I realy like these free chapters It really gives you a feel for the rest of the book and can often save a trip to the books store, especially for a less common title which is often not carried.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.