Title: Adobe Corporate Template 2005
1What is Actionscript 3?
Actionscript 3 is the latest version of the ECMA
compliant scripting language for Adobe Flash or
Flex.
Despite a similar syntax between Actionscript 2,
Actionscript 3 syntax can be slightly different,
but ways of interacting with Flash have
changed. More on this is a bit...but first, we'll
look at what tools are available for us to work
in Actionscript 3.
2How do we create (compile) AS3 content?
- Adobe Flex 2.0
- Adobe Flex 2.0 SDK
- Adobe Flash Actionscript 3.0 preview
- Flex 2 is the only official way to develop
Actionscript 3 content right now. - Using Flex 2, you can create and program content
right inside the tool itself. -
3Creating Actionscript 3.0 content with the Adobe
Flash Preview
- The Flash Professional 9 ActionScript 3.0 Preview
is available at http//labs.adobe.com/technologies
/flash9as3preview/ - The Flash 9 alpha is just a sneak preview to let
Flash developers with no interest in Flex to try
out the AS3. - This alpha contains only 1 difference from Flash
8, other than the ability to write AS3 code, and
publish as Flash 9. - The one difference is a property box to type in
what class your root timeline extends from - The Flash 9 Alpha seems like a perfectly
reasonable way to create Flash 9 content, but
remember, its only an Alpha, so be careful of any
bugs!
4Creating Actionscript 3.0 content with the Flex
2.0 SDK
- The Flex 2.0 SDK is available from adobe.com by
going to the Flex 2 product page. - The SDK (or software development kit) is FREE!
- Being free means Adobe only provides you with
command line tools to compile it. There's no
fancy software for layout or writing code (no
IDE). - So to make a free Actionscript 3 project, you'll
have to write all your MXML and/or Actionscript 3
files with a text editor and then use your DOS
command line tool to create your project..... - ....unless there's a better way
5Other ways....
- From
- http//tom-lee.blogspot.com/2006/07/edit-and-compi
le-flex-apps-in.html - Edit in MXML in Dreamweaver, even compile to the
Flex 2 SDK by extending Dreamweaver with some
simple Javascript - Using Eclipse and ANT
- http//www.flex2ant.org
6AS3 vs AS2
- The Display Object
- E4X
- Regular Expressions
- Events
- Loading external assets
- Errors
- Syntax Differences
- Other new things
7The Display Object
- No longer is the MovieClip central to Flash. In
fact, many of the examples in the Actionscript 3
Cookbook don't use MovieClips at all. - Every object that you can put on the stage in
Flash 9, extends (and therefore retains
properties from) the DisplayObject. - All display objects have a location expressed by
.x and .y, and various other properties that
relate to how the object looks on screen. - Many times, a Sprite is adequate to be your on
stage graphic. A sprite is a MovieClip with no
timeline. - There is no more attachMovieClips or swapDepths,
now to add any display object to the stage, you
would addChild. To remove, removeChild. And to
swapDepths, setChildIndex. The index of the
DisplayObject is its depth. The lesser the
index, the lower the depth.
8E4X XML in Flash 9
- E4X is ECMAScript's answer to native XML object
access, and is available in Actionscript 3. - Now XML data is a primitive data type. So now
XML data is as standard as a number, array, or
string. - Accessing XML is now done with dot syntax, and
introduces some funky looking syntax for
attributes - _at_ can access the attribute of the node
- .. can drill down to a nested node at any level
- serves as a wildcard
crayons price 3.29pencils .48blue pen black
pen from the
Actionscript 3 cookbook // find every price
attribute, and add its value to the the total for
each ( var priceXML in cart.._at_price ) total
price
9Regular Expressions
- Regular Expressions are new to Actionscript and
can almost be considered a mini-language itself. - Regular Expressions are used in many, many
programming languages, and even text editors to
find text. - It's like using when searching for files. If
you enter d.txt to search you'll find all txt
files ending with d. - Regular Expressions are the same in theory but
much more complicated. They have a syntax of
their own to do any sort of matching or finding.
10Events in Actionscript 3
- The eventDispatcher class from AS2 is now the
STANDARD way of doing things in AS3. Programmers
like me had the option before of never using
events. - Now, its absolutely required, and internal to the
Flash Player, rather than an external optional
class. - It's so required, that its the only way to handle
events like onEnterFrame, onRelease, onRollover,
onRollOut - So....there's no more this.onRelease function()
myfunction - things like this MUST be handled with events.
- Another thing worth noting, is that the Static
variable or function type is nothing new in
object oriented programming, but Adobe's AS3
classes use lots of static constants for event
messages
11Loading External Assets
- Loading external assets is now a little different
from AS2. - We used to use loadMovie, or loadMovieNum, or the
MovieClipLoader - Now in AS3, we use our URLRequest object passed
into a Loader object. Or in the case of an MP3,
we can use the Sound object and load a URLRequest
object. - var requestURLRequest new
URLRequest(path) - audioPlayer new Sound()
- audioPlayer.addEventListener(Event.COMP
LETE, audioReady) - audioPlayer.addEventListener(Event.ID3,
id3Ready) - audioPlayer.addEventListener(IOErrorEve
nt.IO_ERROR, audioError) - audioPlayer.addEventListener(ProgressEv
ent.PROGRESS, audioProgress) - audioPlayer.load(request)
-
12Syntax Differences between Actionscript 2 3
- Return value of Void in AS2 is now void in AS3
- All classes must now be in packages
- No more ._ access of properties. It's all .
access
13Errors
- Unlike previous versions of Flash, Flash 9 will
no longer silently ignore your run-time errors. - Now, Actionscript 3 supports Try...catch...and
finally. - If you have code you think might produce an
error, put it in a try block, if it can't run,
your catch block will run. The finally block
will run either way. - function someFunction()Void
- try
- throw new Error()
- trace("try")
-
- catch (errObjectError)
- trace("catch")
- return
-
- finally
- trace("finally")
-