Chapter 5. ActionScript Basics for Flex Applications

IN THIS CHAPTER

Getting Ready

Dot Notation

Inline ActionScript

Assignment and Concatenation

Functions

Variables

Data Types

Objects

Classes

ActionScript’s Relationship with MXML

Comments?

Summary

“A good chemist is twenty times as useful as any poet.”

Ivan Turgenev

ActionScript is the glue that holds your application together. As you know, you’ll use MXML to establish an application’s layout and structure,; in contrast, you’ll use ActionScript to manage interaction, event handling, and processing logic.

Knowing where to place your script, how to create reusable code, and other scripting basics will help you build more powerful applications. Recognizing how ActionScript and MXML work together is key to understanding the Flex framework. In this chapter, you’ll gain the knowledge you need to start making an impact with this powerful programming language.

Getting Ready

In this chapter, we’ll finish the HelloWorld application by adding some interaction with ActionScript. So go ahead and open that project again; the code is shown in Example 5-1.

Example 5-1. The HelloWorld application, going into the final round
<?xml version="1.0" encoding="utf-8"?>
<s:Application
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    width="100%" height="100%">

    <s:Label id="titleLabel" x="50" y="50"
        fontFamily="Arial" fontWeight="bold"
        text="My First Flex 4 Application"/>

    <s:HGroup x="50" y="70

Get Learning Flex 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.