Flash ActionScript 3 overview: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
Line 176: Line 176:
[[AS3 Useful links]], Documentation Links, Reference manuals, Reference manuals, AS2 vs. AS3 comparisons, Overviews, and more.
[[AS3 Useful links]], Documentation Links, Reference manuals, Reference manuals, AS2 vs. AS3 comparisons, Overviews, and more.


== Tutorials ==
* [[AS3 Links Tutorials|On-line Tutorials]]
 
=== General AS 3 Tutorials ===
 
* Adobe's [http://www.adobe.com/devnet/flash/ Developer Center] includes many "quickstart" articles but also more substantial tutorials and finally book excerpts. Examples:
 
** [http://www.adobe.com/devnet/flash/articles/filtering_data_e4x_print.html  Filtering XML data in Flash applications using ECMAScript for XML]
** [http://www.adobe.com/devnet/flash/quickstart/datagrid_pt3/ Filtering and formatting data in the DataGrid component]
** [http://www.adobe.com/devnet/flash/actionscript.html ActionScript and object-oriented programming] (several good tutorials at Adobe's Flash Developer Center)
** [http://www.adobe.com/devnet/actionscript/articles/as3_cookbook_excerpts.html ActionScript 3.0 Cookbook excerpts: From custom classes to the rendering model] (Several free chapters of this book)
** [http://www.adobe.com/devnet/actionscript/#migrating_as3 Migrating your Flash applications to ActionScript 3.0]
 
* [http://www.senocular.com/flash/tutorials/as3withflashcs3/ Getting Started with ActionScript 3.0 in Adobe Flash CS3]
 
* [http://www.actionscript.org/resources/categories/Tutorials/ Tutorials] at ActionScript.org has several action script tutorials, e.g.
** [http://www.actionscript.org/resources/articles/611/1/Getting-started-with-Actionscript-3/Page1.html Getting started with Actionscript 3]
 
* [http://www.kirupa.com/developer/flash/index.htm Kirupa], e.g.
** [http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm Using XML in Flash CS3/AS3]
 
 
 
* [http://www.flepstudio.org/english/blogsection/tutorials.html Flepstudio] has a series of tutorials.
 
* [http://www.flash-db.com/Tutorials/ Flash-db.com] has a series of tutorials.
 
=== Component programming ===
 
(to sort out)
* [http://drawk.wordpress.com/2007/06/03/as3-mouse-events-and-mouse-related-user-actions/ AS3 Mouse Events and Mouse Related User Actions] by Drawk - Really useful.
 
* [http://blog.benstucki.net/?id=19 Quick Tips for Making ActionScript 3 Components] by Ben Stucki.
 
* [http://www.kirupa.com/forum/forumdisplay.php?f=141  ActionScript 3.0 Forums] at Kirupa.com. Also includes [ ActionScript 3 Tip of the Day]
 
* [http://www.kirupa.com/developer/flashcs3/animating_dynamic_movieclips_AS3_pg1.htm Animating Dynamic MovieClips in AS3] by Kirupa.
 
* [http://www.kirupa.com/forum/showthread.php?t=101228  Sending Variables to PHP from Flash And Back again!] (AS2)
 
* [http://blog.3r1c.net/ Eric Cancil]. A blog with AS3 code.
 
* [http://www.uza.lt/ $.console] A console for debuggin, pops up over your application (looks good, not tested so far).
 
=== AS 3 Example-based tutorials ===
 
* [http://www.webwasp.co.uk/tutorials/102/index.php Flash Tutorial - Copy Motion as ActionScript 3.0]
* [http://as3.metah.ch/ Metah.ch] has a series of tutorials with source code.
 
=== AS 3 Examples ===
 
* [http://www.zeuslabs.us/flex-2-treemap-component/ Flex Treemap Component]
* [http://drawk.wordpress.com/2007/06/25/updated-list-of-best-animation-packages-for-as3/ Updated: List of Best Animation Packages for AS3]
* [http://labs.zeh.com.br/blog/?p=100 On user-triggered and user-controlled interface animation]


== Reusable components and libraries ==
== Reusable components and libraries ==

Revision as of 17:01, 31 October 2007

<pageby nominor="false" comments="false"/>

This is part of the Flash series of articles. But it is not a tutorial !!

Introduction - Writing and using AS Code

“ActionScript 3.0 is a dialect of ECMAScript which formalizes the features of ActionScript 2.0, adds the capabilities of ECMAScript for XML (E4X), and unifies the language into a coherent whole.” (Grossman, 2006).

Basically, there are different ways of using ActionScript 3:

1. Within a Flash CS3 environment:

  • Use the Flash CS3 environment more less as "in the ActionScript 2" way, i.e. you add bits of code to certain frames
  • Write action code with a class structure in a file, then import to a frame through the properties panel.
  • Write your code in a file and compile it (you also may use Flash CS3 that way). No drawings, just code !

2. Within an Adobe Flex environment: Flex is a framework introduced by Adobe that also compiles into swf files. Flex is meant to make it easier to conceive rich Internet applications that contain a variety of interactive interface elements (buttons, textfields, lists of images, etc.). The Flex SDK is free to use but lives in a command line environment. Flex Builder provides a visual development environment. It is due to become free for students and educators starting early November.

Using ActionScript like a Flash Designer

  • Create a new layer
  • Click on a frame (typically frame 1)
  • Hit F9, the copy/paste or write your code

This is the way most of the Flash examples made in our tutorials were made

Scripting in the timeline does not require from you to use classes. However, sometimes you need to import packages, i.e. when Flash whines that it can't find a method. Examples are:

import Fl.managers.FocusManager; // to work with keypress events
import fl.video.MetadataEvent;  // to work with cue points in flv videos

Using ActionScript classes in CS3

Most examples in the official Using ActionScript 3.0 Components and ActionScript 3.0 Language and Components Reference are made with a class structure and require that you learn this (read also Using examples in the ActionScript 3.0 Language Reference):

  1. Write code in a AS file and give the file the same name as the primary class (for example: ContextMenuExample.as).
  2. Create and save a new empty FLA file in the same directory as the AS file.
  3. In the Properties tab of the Property inspector enter the class name of the primary class for the example in the Document class text box (for example: ContextMenuExample).
  4. Save your changes to the FLA file.

Note for Flash designers: Some of the code in the Flash doc can be fairly easily simplified to work with the simple timeline scripting method. Other can not and you do have to code with a "class structure".

Stand-alone code development with AS 3

You do not need to buy Flash CS3 (that's actually a cool thing) to program in AS3 and to create *.swf files. You can either use:

  • Flex Builder - an Eclipse plugin
  • Just the Flex SDK

Read on how to install the Flex Framework on the Flex page.

Using the compiler
  • Just type something like:
mxmlc HelloWorld.as 

.... This will make an *.swf file

Development support other than Eclipse

I find these IDEs too hard to use (I only occasionally program and just use the Emacs editor and don't want learn full Flex yet). So I need some Emacs code for help with editing (not done yet)

If emacs appears too complex to master, a very easy to use editor in Unix/Linux environments is pico

The class hierarchy

At the origin, there is the Object. It has many subclasses (about 151 I'd say).

EventDispatcher

EventDispatcher implements is the base class for the DisplayObject class, i.e. all displayed objects. It is a direct child of Object and has 29 subclasses. A few are:

The DisplayObject

The ActionScript 3.0 flash.display package defines a whole lot of different kinds of visual objects that can appear in the Flash Player. DisplayObject is a child of EventDispatcher, child of Object

Below is summary table of ActionScript 3 interactive display objects. It shows that interactive objects are defined as hierarchical classes. Methods and properties that work for a parent class (e.g. Sprite) also will work for its child classes (e.g. UIComponent). Links point to the technical reference manual at Adobe.

Events

The Event class is used as the base class for the creation of Event objects, which are passed as parameters to event listeners when an event occurs. Event is a direct child of the object. There are 26 direct subclasses and Flex has even more. We only will show a few here.

Interfaces:

When Flash executes

The display list

At at given time in your animation, your Flash application contains a hierarchy of displayed objects: the display list. It contains all the visible elements and they fall in one of the following categories:

  • The stage: Each application has one stage object and it contains all on-screen display objects (i.e. containers or simple objects). This includes objects that the user can't see (e.g. ones that are outside of the stage).
  • Display object containers, i.e. objects that can contain both simple display objects and other display object containers.
  • (Simple) display objects

Stage and Timeline

“To summarize: one stage, one root per SWF (which is the main timeline) and that root is an instance of a document class or the MainTimeline class if a document class isn't provided”

AS 3 coding notes

(I will kill this section later ... i.e. once I got some tutorials with code inside)

Event handling

General pattern

Definition of an event handler function:

function eventResponse (eventObject:EventType):void
 {
   // Actions performed in response to the event go here.
 }

Using it:

eventSource.addEventListener(EventType.EVENT_NAME, eventResponse);
Example
launch_button.addEventListener(MouseEvent.CLICK,launchRocket);

function launchRocket(event:MouseEvent):void {
    gotoAndPlay(2);
}

See ActionScript 3 event handling tutorial. You also can see an example in the Flash button tutorial

Useful Links

AS3 Useful links, Documentation Links, Reference manuals, Reference manuals, AS2 vs. AS3 comparisons, Overviews, and more.

Reusable components and libraries

  • Tweener Tweener (caurina.transitions.Tweener) is a Class used to create tweenings and other transitions via ActionScript code for projects built on the Flash platform.
  • TweenLite. TweenLite (AS3) - A Lightweight (2K) Yet Powerful Tweening Engine.
  • TweenFilterLite. TweenFilterLite extends the extremely lightweight (2k), powerful TweenLite "core" class, adding the ability to tween filters (like blurs, glows, drop shadows, bevels, etc.) as well as image effects like contrast, colorization, brightness, saturation, hue, and threshold (combined size: 5k).
  • WebORB for PHP (should be moved to Flex). erver-side technology enabling connectivity between Flex and Flash Remoting clients and PHP applications.

Other

Development environments

Blogs and stuff