You are currently browsing the category archive for the 'ActionScript 3.0 Notes' category.

Author: Ashwinee Kumar Dash.

Name of the Book: Essential ActionScript 3.0 by Colin Moock

Copyright: Creative Commons License
Disclaimer: Anything in quotation marks is a direct quotation from Essential
ActionScript 3.0
. All other notes are my own summaries of the concepts
presented in the book.

These notes are for reference purpose only and not intended to replace the book .Therefore I would strongly advise you to read the original book as well as make your own notes wherever necessary.

Send your suggestions and feedbacks to aswhineedash[at]gmail[dot]com or aswhinee2004[at]gamil[dot]com.

Data Type

  • Data Type means a set of values.
  • Null, void and object are three data types in AS.
  • Null has null value
  • Void has undefined as its value
  • Object includes all the instances of all the classes in ActionScript.
  • Each class creates a unique datatype. Its values are the instances of the class itself and its subclasses.
  • Any given subtype is compatible with its supertype and likewise a supertype is incompatible with its subtype. That’s because an instance of subclass can be treated as an instance of its superclass.
  • A type annotation or type declaration is a suffix that constrains the datatype of a variable parameter or function return value.
  • Type declaration is preceded by colon “:”.
  • In case of variable or function parameter the data type must be a class or interface.
  • In case of return type the data type must be a class, interface or void.
  • They can take * as data type which means untyped.
  • 3 situations where data type mismatch error is ignored in strict mode until runtime (1) untyped expression assigned to typed variable or parameter or returned from a function with a declared return type (2) any expression assigned to a typed variable or parameter with Boolean datatype or returned from a function with a Boolean return type (3) any numeric type is used where a different numeric type is expected
  • To detect reference errors compiler relies on type annotations.
  • Compiler checks the method definition in the class or interface which is specified by variable’s type annotation.
  • Compiler does not check the actual class of the value.
  • To avoid such errors at the compile time cast operation is used.
  • Cast operation tells the compiler to treat the expression as a specified type.
  • Type (expression).
  • At the runtime if the expression resolves to the specified object, it is returned.
  • If it does not resolve to a specified object, either it is converted to a primitive datatype or an error is generated.
  • Casting an object to its supertype is known as upcast
  • Casting an object to its subtype is known as downcast.
  • Upcast never generates an error
  • Downcast has the potential to generate error
  • To check the data type of an object, the ‘is’ operator is used like (expression is type) which returns a true or false value.
  • A cast operation can be used to convert any value to a particular primitive type.
  • When a variable is declared without a type annotation and without an initial value, its value is set to undefined.
  • If a variable is not initialized, it takes the default value of its datatype.
  • Both null and undefined means absence of data
  • The null value represents the absence of data for variables, parameters and return values with any type annotations except Boolean, int, uint, and number
  • Undefined represents absence of data for variables, parameters or return values without any specified type annotations
  • Undefined also means complete absence of variable or method on an object whose class is defined as dynamic

Author: Ashwinee Kumar Dash.

Name of the Book: Essential ActionScript 3.0 by Colin Moock

Copyright: Creative Commons License
Disclaimer: Anything in quotation marks is a direct quotation from Essential
ActionScript 3.0
. All other notes are my own summaries of the concepts
presented in the book.

These notes are for reference purpose only and not intended to replace the book .Therefore I would strongly advise you to read the original book as well as make your own notes wherever necessary.

Send your suggestions and feedbacks to aswhineedash[at]gmail[dot]com or aswhinee2004[at]gamil[dot]com.

Instance Methods

  • The keyword this can be omitted as ActionScript automatically searches for the instance variable or method unless there is a local one available matching the search result.
  • Usage of the keyword this is legal only in the following cases instance method, constructor method, functions and code in global scope.
  • Method can be assigned as value to variable and again can be invoked through that variable. Such methods are known as bound methods.
  • This is most used when one section of program wishes to instruct another section of the program to invoke a particular method on a particular object.
  • Get method is used to retrieve the value of the private instance property
  • To define get method get keyword is used.
  • Get methods have a return type as they have the return value
  • Similarly set methods are used to modify the values of variables.
  • To define a set method set keyword is used.
  • Unlike get methods set methods do not have return values.
  • To invoke set or get methods “()” is not used.
  • In case of set methods a value is assigned rather than any arguments are passed
  • To deal with unknown number of parameters ….(rest) can be used where (rest) is the array of arguments. Just like any array arguments can be retrieved using array index.

Author: Ashwinee Kumar Dash.

Name of the Book: Essential ActionScript 3.0 by Colin Moock

Copyright: Creative Commons License
Disclaimer: Anything in quotation marks is a direct quotation from Essential
ActionScript 3.0
. All other notes are my own summaries of the concepts
presented in the book.

These notes are for reference purpose only and not intended to replace the book .Therefore I would strongly advise you to read the original book as well as make your own notes wherever necessary.

Send your suggestions and feedbacks to aswhineedash[at]gmail[dot]com or aswhinee2004[at]gamil[dot]com.

Static Variables and Methods

  • Static variables are class variables, not instance variables. Static variables do not vary from instance to instance
  • Static keyword defines the variable to be a class variable
  • Four access control modifiers available and they are public, private, internal and protected. These modifiers come before the static keyword.
  • Inside the class static variables can be used as regular variables. But otherwise it has to be accessed by using className.variable.
  • Inside a class a static variable and an instance variable of same names can coexist.
  • Constant is a variable with a value that do not change throughout the program
  • It is defined using the keyword const in stead of var
  • Like static variables, static methods define functionality that relate to an entire class.
  • Static methods cannot use the keyword this.
  • Static methods cannot access instance variables and instance methods of the class where it is defined. quite logical.
  • When ActionScript creates a class at runtime, it creates a method called class initializer and runs it.
  • In the class initializer it places all the static variables and all class level code that is not instance variable or instance method.
  • Every class in ActionScript is represented at runtime as an instance of the Class class.
  • Class objects are primarily used to access static properties and static methods.
  • Like other objects class objects can be used as values for assigning and return type.

Author: Ashwinee Kumar Dash.

Name of the Book: Essential ActionScript 3.0 by Colin Moock

Copyright: Creative Commons License
Disclaimer: Anything in quotation marks is a direct quotation from Essential
ActionScript 3.0
. All other notes are my own summaries of the concepts
presented in the book.

These notes are for reference purpose only and not intended to replace the book .Therefore I would strongly advise you to read the original book as well as make your own notes wherever necessary.

Send your suggestions and feedbacks to aswhineedash[at]gmail[dot]com or aswhinee2004[at]gamil[dot]com.

Classes

  • Classes are the blue prints upon which objects are built.
  • Every object that you see in a program has a class of its own.
  • Classes written from scratch known as custom classes.
  • Built in classes are used to perform some fundamental tasks
  • Classes built directly into ActionScript are known as native classes.
  • Classes are created by using class keyword. Read the rest of this entry »

I would like to thank Colin for allowing me to publish my own notes that I had jotted down while studying his (essential) book aptly titled Essential ActionScript 3.0.

EAS 3.0

In my opinion it is the best book currently available to learn Object Oriented Programming using Actionscript 3.0. The following three categories of readers can benefit from the book

  • those who are new to OOP and AS 3.0 ( they will find it most useful).
  • those wishing to upgrade from AS 2.0 to AS 3.0 will need this book to understand concepts like e4x, display architecture, Flash player security and events and event handling etc.
  • C# or C++ or java developers wishing to use AS 3.0 in their Flex projects won’t find such in depth knowledge and coverage of AS3.0 in any other book.

The importance of AS 3.0 has increased in these days due to quick adoption of Flex and to use Flex to its fullest extent one must know AS 3.0 inside out . When it comes to ActionScript, nobody teaches you the better than Colin Moock.

I, like countless others have learnt a lot about ActionScript and Flash just by reading his books. I hope he continues to write more about ActionScript, a popular language destined to become.

Currently it is not posssible to create a screen capture application using AS 3.0 and AIR Beta 1.

I built a demo screen capture application to test the fact.

Here is the screenshot of the application:

scr
Image created and saved by the application:

ashwinee

Here is the code of the application I built to test the fact.

Read the rest of this entry »

Imtiyaz.m.s has compiled a comparison between Java 5.0 and ActionScript 3.0 in his blog. Here is the link http://msimtiyaz.wordpress.com/flex/java-and-actionscript/

And don’t forget to view the comments here http://msimtiyaz.wordpress.com/2007/08/05/mfug-2/

Update

Detailed comparison can be found in the book Rich Internet Applications with Adobe Flex and Java .

This book is written by Yakov Fain, Dr. Victor Rasputnis, Anatole Tartakovsky.
 

I have recently downloaded The Essential Actionscript 3.0 by Colin Moock (still in the Rough Cuts version) from O’reilly’s Safari Online. This book is 861 pages long in its PDF version( a big book).
Day 1
So far I have read only the preface, acknowledgment and some pages of Core Concepts(chapter 1).Like the AS itself, the book has got a whole new approach to teaching programming.This book is about programming and uses AS to teach Object Oriented Programming.It starts with classes and packages and then goes on to teach variables and functions etc.In the section titled Beginners welcome, it is clearly stated that no prior programming knowledge is assumed.Every book says that but really a few provide a good guideline to newbies.

About accuracy and depth of coverage.
Consider the following stat about this book
Years of research : 2
No. of reviewers : 15
No. of pages : 861
No. of supporters : Still counting (ever heard of Mike Chambers)

I think this is enough to give this book a try at least.

Day 2

Read a few more pages of Chapter 1 Core concepts.Moock starts from the top with package and then moves on to classes and then talks about constructor and variables. Dave Thomas also wanted to start from the top but he had this dillema how to tell about classes and objects without first telling about the basic building blocks of programming like variables and functions.But Moock has done it.And like me, you would not believe it unless you read on your own.

I, like others always used variable initializer but I was unaware of it till I read it in the book.

If you are wondering what this means, then read the following excerpt from the book

“class SomeClass {

public function SomeClass () {
var identifier = value;
}

}
In the preceding code, identifier is the local variable’s name, and value is the value
associated with that variable. Together, the equals sign and the value are known as the
variable initializer because they determine the initial value of the variable.
NOTE
Associating a variable with a value is known as assigning, setting, or writing the
variable’s value.
When the variable initializer is omitted, ActionScript automatically assigns the variable a
default value.”

Let me read a little more…

If Apollo can’t access database,then how does it work ?

In the true tradition of macromedia Adobe once more has let us down.Last time you saved anything from a flash movie was in the times of Flash 5.After Flash 5 the security tightened and nothing can be saved from swfs.You can draw a picture or write some notes and even use ‘Ctrl+C’ and ‘Ctrl+V’ but no ‘Ctrl+S’ while your favorite movie plays or waits for your active response.

But you will say “Don’t forget Local shared Object”.And I will say “Wow, that’s great.Actually LSO has saved me many times in my coding career.”

But we all know that is not enough.We need some kind of database access to develope enterprise level applications.

The next question is if an Apollo app cannot access databse then how is it going to deal with data?

Ans:

Adobe has alaready shown a really cool demo of ebay apollo app.

Still want to know more..

Let’s analyse the objective with which Apollo framework is created and we will clearly see why database access is not on its to-do lists.

Reason 1:

Its primary objective is to connect the system(desktop) with the application running on the server.

Reason 2:

Its job is not to replace either the browser or the server side languages but rather to complement them.

Reason 3:

Any server side language can access the database in better ways as they are built to do that.(save us learning a new language)

Then how does the app work?

Before we go further give a look at the class and package structure of the Apollo(refer my Apollo Class heierarchy.swf)

It has got the following actionscript packages

flash.display
flash.events.FileListEvent
flash.filesystem
flash.html
flash.system

This clearly shows what is being dealt with here.
Apollo is a framework which leverages the power of Flash,Actionscript,html,css and javascript in addition to some native functionalities and APIs such as file I/O and native windowing etc.

From this I can safely deduce that Apollo application will work in the following manner(see the blow diagram).

apollo-app-structure.gif
The app renders the html and display contents from the server.It saves the required data in the system in some format so that it can operate when offline.Apart form this, it can read/write files and can access system directories.So any modification done by the user is saved and uploaded once the app goes online.

Javascript support means developers do not have to write user interactions,client side validations twice.Once in javascript and again in actionscript.

It seems without direct database access an apollo app can do a lot.

I have created a tree structure of Apollo classes and packages that gets added to the existing mx and flash packages as well as some new properties/methods that have been added to some classes.

This will come handy while developing Apollo apps.

Download the .swf 

Apollo Class Hierarchy

I have created the tree view of Flex class hierarchy in flash.The root class is Object and other classes extend it. You have to click on the folder icon to see its subclasses.

Flex Class reference

You can see it in action at the following link.

http://www.ashwineedash.com/template_permalink.asp?id=114

Also you can get the download link from there. Read the rest of this entry »

Abstarct classes are not supported in AS 3.0.It was not supported even in AS 2.0.

Supported class types:

dynamic

internal(default)

final

public

Unless any attribute is defined for a class,it will be internal type.this means it is accessible inside the current package.