Flash Mobile: Developing Mobile Apps using ActionScript: Developing Mobile Apps using ActionScript [NOOK Book]


First Published in 2010. Routledge is an imprint of Taylor & Francis, an informa company.
Read More Show Less
... See more details below
Flash Mobile: Developing Mobile Apps using ActionScript: Developing Mobile Apps using ActionScript

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac

Want a NOOK? Explore Now

NOOK Book (eBook)
BN.com price
(Save 7%)$5.95 List Price


First Published in 2010. Routledge is an imprint of Taylor & Francis, an informa company.
Read More Show Less

Product Details

  • ISBN-13: 9780240815756
  • Publisher: Elsevier Science
  • Publication date: 1/1/2011
  • Series: Visualizing the Web Series
  • Sold by: Barnes & Noble
  • Format: eBook
  • Pages: 42
  • File size: 533 KB

Meet the Author

Matthew David is a specialist developing rich Web solutions using technologies like Flash and the latest Web design techniques. In addition, he works in online sales, marketing, and search engine optimization, with the aim of driving business to customer sites. Matthew partners with many companies as a business strategist, works closely with the World Wide Web Consortium Group (W3C), and is on Adobe's Advisory team.
Read More Show Less

Read an Excerpt



Focal Press

Copyright © 2011 Elsevier Inc.
All right reserved.

ISBN: 978-0-240-81575-6

Chapter One


Do you like Flash games and cool features on YouTube, like jumping from standard view to HD? There are two faces to Flash: the one you see and the complex scripting engine, called ActionScript, that you don't. Without ActionScript, Flash would not be interactive. ActionScript is the scripting language built within Flash that allows you to build interactive solutions. Any Flash movie where you need to click, drag, or pause requires ActionScript to instruct Flash what to do (Figure 3.1).

Flash CS5 allows you to build applications using two different versions of ActionScript. The older versions are ActionScript 1.0 and 2.0, or AS1 and AS2. AS2 is backward-compatible with AS1 applications. The release of Flash CS3 introduced ActionScript 3.0 (AS3), which was a significant overhaul of the scripting language. AS3 has adopted a true object-oriented approach to development, a technique that allows Flash applications to compete with solutions developed with Microsoft's .NET or Oracle's Java. Complex solutions often require a lot of code, and older versions of ActionScript ran slowly with large and complex scripts. AS3 changed this. AS3 is as much as 10 times faster than AS2, and brings much more functionality to the party. In short, AS3 brings it on.

ActionScript 3.0 is the only way you can create solutions for the iPhone and Android OS. You will not be able to use AS1 or AS2 for this application.

In this chapter you will learn why you'll want to start using AS3, what has changed from and what is the same as earlier versions of ActionScript, and how you can make your applications rock by using AS3.

Enabling Flash to execute solutions Faster with AVM 2.0

The Flash Player, the plug-in you install in your web browser to playback Flash SWF files, is the key to success in building fast applications. To compile and then run any ActionScript in your Flash movies, the Flash Player uses a tool called the ActionScript Virtual Machine (AVM). For AS1 and AS2 the Flash Player uses AVM 1.0. The Flash Player 9 introduced a brand new AVM, called AVM 2.0, that is dedicated to running just AS3 application files. To put it simply, AVM 2.0 rocks: It makes your code zip along.

Developing AS3 solutions that are targeted at the AVM 2.0 rendering engine will ensure your have highly optimized Flash solutions.

What You can expect When You use AS3

ActionScript 3.0 is a rewrite of ActionScript that brings it completely up to date with current development best practices. There are number of big changes that will take a while to get used to. The main changes are:

• ActionScript is located in Class files or in the Timeline.

• Code design is truly object-oriented.

• You cannot add ActionScript directly to movie clips or buttons instances.

• Triggering events has changed.

• Loading data has changed.

• XML is managed differently.

There are a score of smaller changes. As you dive directly into AS3 you will find a learning curve as you move from AS2. Is it all worthwhile to go through the pain? Absolutely. AS3 is simply so much faster and more powerful that it is worth the undertaking.

It is also the only way you can get your mobile apps to run on Android and iOS devices.

The Main Features of AS3

ActionScript is object-oriented in design concept. But what the heck does that mean? If you have developed for other programming languages, such as Java, C++, or C#, then you have heard of this term. Object-oriented essentially means that you break code into objects that can be easily reused. The idea is this: It is easier to manage an application that has a collection of smaller files than one large file.

There are two ways in which you can manage your ActionScript. The first, more traditional method is to add your ActionScript to the timeline (Figure 3.2). This will be familiar to earlier Flash developers. A good practice to establish is to have a layer in your timeline that is dedicated to working just with ActionScript. Adobe recommends that you label the ActionScript label "Actions." Locking the Actions layer will prevent you from accidentally adding movie clips into it.

The second method of inserting ActionScript into your Flash files is to use a Class file. Class files have a long history in the development world. With the Class file you can now specify both Public and Private Classes. Using the Private keyword restricts the use of the attribute you defined to just that class and it will not be shared with other classes. This is useful as you develop instruction that needs to be executed privately in a closed environment.

Other major changes include:

• Developing solutions built with the DOM3 event model

• Using namespaces in your projects

• Controlling data

• Controlling text

• Drawing with the Shape Class

• The ability to easily work with external ActionScript libraries

All in all, these new changes to ActionScript ensure that you can develop even better solutions, ones that AS2 simply could not enable you to accomplish.

What is the Same between AS2 and AS3?

With all the changes between AS3 and AS2 it important to remember that there is a lot of functionality that is the same between them. This will help as you transition from traditional AS1/2 Flash development to mobile app development using AS3.

For instance you still use the following in the same way:

• Variables

• Math objects

• If/Else statements

• Switch statements

• String

• Date to control the use of date and time

• Array to build a structured collection of data

• Boolean to specify a true or false

The following works in AS2 and AS3:

var str:String = new String("Hello, "); var str2:String = new String("World"); trace (str + str2);

You can see that the overall syntax structure is the same between both versions of ActionScript. You still end your code with curly brackets, your variable names are still case sensitive, your variable names cannot start with a number, and you still use number class objects the same way.

Using Code Snippets to Get You Started

Transitioning to AS3 after your entire career has been spent working with AS2 does come with a learning curve. To help you through the transition, Adobe has included a great new tool in Flash CS5, the Code Snippets panel, which you can use to quickly add popular scripts to your movies. Here's what you do:

1. Create a new AS3 file.

2. Select Windows [right arrow] Code Snippets. This will open the Code Snippets window (Figure 3.3).

3. Code Snippets are organized in groups (Actions, Timeline Navigation, Animation, Load and Unload, Audio and Video, and Event Handlers).

4. Expand the Actions group and double-click Generate a Random Number.

Two things happen: a new layer, labeled Actions, is added to your timeline, and the new Actions layer has ActionScript added to it. The new script is automatically generated by Flash CS5.

The new ActionScript is true AS3. Check out the script by opening the Actions panel. Adobe has added some great inline comments to explain how you can use this script. Figure 3.4 contains a sample of the code that will be generated.

You will see that the code is split into two sections. The first section is a comment that explains how to modify and use the code that is generated. The second is the code itself. Test the movie and you will see a random number appear in the Output panel.

The Code Snippets panel really shows its power for allowing you to learn ActionScript quickly when you add code to movie clips on the stage. Let's go ahead and create a movie clip and then add a sound event.

1. Select the rectangle tool and draw a rectangle shape on the stage. Select the new shape and convert it to a movie clip.

2. Select the new movie on the stage and expand the Audio and Video submenu on the Code Snippets panel and double-click the Click to Play/Stop Sound snippet (Figure 3.5).

3. You will see a warning appear if you have not given your movie clip a name. Flash can do this automatically; select OK to automatically add the code snippet.

4. Open the Actions panel and you will see that the ActionScript to trigger the event has been added (Figure 3.6).

5. Test your movie. Select your movie clip on the stage and the MP3 track will start to play.

You will see that the code is formatted to take advantage of the AS3 event model. For instance, the code is not added to the movie clip itself. The event is created as two parts: a function that explains what is going to happen, and a listener event that triggers the function. Without knowing it, you are using AS3. What you will find very helpful is that you can now go into your ActionScript code and modify it easily. For instance, you can change the path of the MP3 file to one on your own servers, or to point to a live, streamed MP3 file. For instance, you can changetheURLRequest to point to http://mp3-vr-128.as34763. net:80/, a great radio station broadcasting out of London, U.K.

Developing Solutions built with the DoM3 Event Model

ActionScript 3.0 now supports the ECMAScript, DOM3, event model syntax. In laymen's terms, this means that you now use the Listener object to detect when you interact with your Flash movie using either a keyboard, mouse, or the new gesture interfaces used when touching the screen directly.

This is a big move from AS2. As an example, the following script is an AS2 instruction that instructs a movie clip to jump to frame 25 of a movie:

on (release) { this.gotoAndStop("25"); }

ActionScript 3.0 uses Listeners to trigger when an event occurs. Listeners are more complex to work with, but in the end, give you more flexibility. There are essentially two parts to a Listener: The first is a function that describes what is going to happen when you trigger an event, and the second is the Listener that waits for a specified event to happen, such as mouse clicking on a button.

The following steps will add an AS3 event that mimics the same event as the AS2 example earlier.

1. Create a new AS3 file. On the stage create a new movie clip.

2. Label the movie clip "myMovie."

3. Create a new layer in the timeline and name it Actions. Select the new layer.

4. Open the Actions panel. The first step is to create the function.

function gotoFunction(event:MouseEvent):void { gotoAndStop(25); }

5. The function is called "gotoFunction"; the parentheses dictate that it is looking for a mouse-driven event. There is only one instruction in the function, the gotoAndStop function that will move the Timeline to frame 25.

6. Add the listener that will look to trigger the function.

myMovie.addEventListener(MouseEvent.MOUSE_UP, gotoFunction);

7. The first change is directly related to all AS3 needed placement in the timeline or in a Class file: On the stage is a movie clip labeled "myMovie." Use ActionScript to control the "myMovie" clip.

8. The second part of the Listener, addEventListener, instructs Flash that you are using the Listener object.

9. In parentheses are two parts, which explain that the event is a mouse event and to use the function gotoFunction.

At first blush, the new AS3 event model appears to be too complex. After all, AS2 is easier to use. The difference between the two is that the AS3 event model gives you flexibility to write more complex scripts and to extend the functionality of the event model beyond traditional mouse and keyboard interfaces. To do this you use the core object class controlling events on the screen, called the EventsDispatcher class. Through this you can not only leverage standard events such as mouse clicks and the keyboard, but you can extend the class with your event types.

Working with classes

A common design pattern in object-oriented programs separates design, programming, and data elements. Flash CS5 adds this functionality with the inclusion of classes. A class is a packaged document that you can use to explain how UI components, business logic, and data elements will interact.

A class is a separate ActionScript file that is associated with the main Flash file and movie clips. You can use Flash CS5 as the class file editor or your favorite text editor such as Eclipse, Notepad, or TextEdit. A Class file is only a text file. It is very easy to create entire Flash movies using just Class files and not even add any content into a traditional timeline.

These steps will show you how to create a simple Class file for your Flash movies:

1. Create a new AS3 file. Save the file and name it "helloWorld.fla".

2. In the new, blank helloWorld.fla file open the Properties panel.

3. Expand the Publish setting. You will see a Class field. To the right-hand side of the Class field is a small pencil icon. Select the icon. A new window will open asking you if you want to create a new class. Create a new class and call it helloClass.

4. A new ActionScript file will open. Notice that the file is now labeled helloClass. The class is a default, blank class with the ActionScript shown in Figure 3.7.


Excerpted from DEVELOPING MOBILE APPS USING ACTIONSCRIPT by MATTHEW DAVID Copyright © 2011 by Elsevier Inc. . Excerpted by permission of Focal Press. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents


Enabling Flash to Execute Solutions Faster with AVM 2.0....................66
What You Can Expect When You Use AS3....................66
Controlling Data....................77
Controlling Text....................80
Drawing with the Shape Class....................81
Using ActionScript to Control Animation, Audio, and Video in Your Android Apps....................82
Extending Flash with Open Source Libraries....................89
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)