09 August 2006

ActionScript - a Prototype vs. Class based language

Written by Richard Leggett ( Contact the author of this post )
Published on August 9th, 2006 @ 04:31:53 am, using 249 words, 844 views
Categories: Flash, General

I was just asked by a friend, "if code on the timeline in Flash 8 is no different from AS1 because it isn't inside a class file [therefore not type-checked or anything else that typically differentiates AS2 from AS1], what is AS3 code on the timeline in Flash 9?".

I didn't have a simple answer. That code will still be runtime checked etc, it certainly isn't AS1 or AS2. The reason we can't define what it is exactly is probably due to the nature of the language.

ActionScript has class structures, but they aren't the same behind the scenes as classes in what we call traditional class based languages, they are actually collections of "traits" and "property attributes" on an object prototype. If those terms are new to you, you might find the following paper of interest.

I found this paper quite some time ago probably through MXNA, and it has stuck in my mind since I first read it, it gave me a much better understanding of how a prototype language is very different to anything else, and how that makes it very suitable for GUIs which is the subject of the article.

It's a bit old, but 100% worth the read.

http://waltersmith.us/wp-content/uploads/2005/12/OOPSLA95.pdf

That paper doesn't really get technical enough, but there's a lot more info on this matter in the LiveDocs which directly related to ActionScript. The pages in that particular LiveDoc are really good reading if you like to look behind the curtain.

Comments, Pingbacks:

Comment from: Emmanuel Okyere
Afaik, there are statically-typed and scripting languages; that they have their compilation units as classes or not, I think, is mostly a matter of organisation. Languages like Java, however afaik, have the idea of a class deeply ingrained in the language spec and the way developers are supposed to approach it.

Actionscript grew in that direction, afaik, from the way earlier developers approached it.

Cheers,
Emmanuel
PermalinkPermalink 09/08/06 @ 04:53
Comment from: Richard Leggett [Member] Email
Yes precisely, I didn't even go into the topic of statically typed vs. dynamic languages, that's a whole other topic, but it's still very much linked (you don't find too many statically typed prototype based languages though).

Really, I find it interesting that AS3 looks so much like Java, but works in a very different way, and that makes it harder to predict in certain situations, but also more flexible in others!
PermalinkPermalink 09/08/06 @ 04:57
Comment from: Osc23
Senocular's amazing set of daily AS3.0 tips may hold the answer in that timeline's are converted into classes...

"If you do not associate a timeline with a class, one is automatically created for that timeline by Flash. When this happens, variables become class variables, all named functions (declared using function functionName(){}) become methods of that class, and all scripts within the frames associated with methods that are automatically called when that frame is reached (minus the variable and method definitions)."

http://www.kirupa.com/forum/showthread.php?p=1914661#post1914661

Hope this helps

Osc23
PermalinkPermalink 09/08/06 @ 06:46
Comment from: Osc23
This link is to a page with all the tips listed and may show up better than the long link I just posted.

http://www.kirupa.com/forum/showthread.php?t=223798

Sorry for posting twice ;)

Osc23
PermalinkPermalink 09/08/06 @ 06:50
Comment from: senocular
And it works backwards for AS2 where class code is placed on the timeline during compile time in the form of #initclip (AS1 code) #endinitclip in movie clip symbols specifically created to contain each AS2 class used. The only real advantages of AS2 classes are organization, syntactical preference, and "Class" type compile time checking (which, really, aren't bad things).

The tips Osc23 posted also go to explain the use of the prototype object in AS3 - where though it is not the primary means of inheritance, it still exists in AS3 (mirroring the inheritance chain of the class) and can still be used to assign members to a class dynamically as you could in AS1 and AS2.
PermalinkPermalink 09/08/06 @ 07:39
Comment from: Richard Leggett [Member] Email
Very nice links, thanks guys.
PermalinkPermalink 09/08/06 @ 11:07
Comment from: subhero
nothing substantial but maybe complemental:
something that opened my eyes to the subject "class based vs. prototype":
http://www.zwetan.com/blog/ECMAScript/RaisingHell.html

it is also advisable to simply read the ecma-specs or the "prototype based languages"-pdf (linked from zwetan's post).
although it seems something changed in the as3-prototype implementation regarding inheritance. don't know exactly but got burrned by tink once about this subject ;)

hope it's useful
-sh
PermalinkPermalink 09/08/06 @ 13:09
Comment from: Richard Leggett [Member] Email
Hey sh,

Yeah I remember they changed the way inheritance and prototype lookups work. Again thanks for the link, keep them coming! :)
PermalinkPermalink 10/08/06 @ 04:12

Comments are closed for this post.

About

Richard Leggett is a Freelance RIA and Web Developer (download CV, skills/portfolio coming soon). He is co-author of Foundation Flash Applications for Mobile Devices (Friend of ED), an Adobe Community Expert and speaker at industry conferences and user groups.



July 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Categories

Miscellany

XML Feeds

Information

Contact the admin  /   b2evo template by Two18 Media