gskinner.com: gBlog: FlashMX 2004 source code, news, reviews and opinions
Back to gBlog Main gskinner.com website: source code, portfolio, etc. contact Grant Skinner

Syndication
RSS 1.0
RSS 2.0


Subscribe
Enter your email address to be notified when posts are added.

Search

Resources
Conference Session Notes

Flash Blogs
Waxpraxis
Philterblog
W3Blog
Jonas Galvez
Josh Dura
Quasimondo
Flashguru
Sean Voisen
Colin Moock
Flazoom
Greg Burch
Pope De Flash
Peter Hall
Glyn Thomas
actionscript.com
Princess Pegg


Aggregators
Flog
FullAsAGoog
MXNA
Hall of Justhese


« Lots of OOP in AS2.0 goodness | Back to Main | A little house cleaning »

September 09, 2003


IMPORTANT NOTE: This is an old archive. It is only here to support outdated external links. To view the updated version of this archive, please go to the blog index, and search for the title of this document using the search form.

OOP4AS2#1: Classes and instances
Posted by Grant
This post on classes and instances begins my little exposé on ActionScript 2.0 and Object Oriented Programming. I won't be going into tons of detail (for that you'll have to buy the forthcoming "FlashMX 2004 Demystified" book from Macromedia Press!), but I'll be giving a basic introduction.

I'll also be covering a lot of these materials at FlashParade in October, and more briefly at the next Edmonton Flash User Group meeting on September 15.

Read on for the real content... :)

In ActionScript 2.0, we have finally been blessed with an actual "class" keyword, which thankfully means that you no longer have to define classes as bastardized functions. Defining functions is really easy too, just create a class block, and put the methods and properties you wish to assign to the class inside its brackets:

class GThing {
  // ain't nuthin but a GThing, baby.
   var pureGoodness = true;
   function canIGetSomeLove() {
      return"love";
    }
}

I won't go into details about typing and actually defining properties and methods here - I'll cover it separately in another post. Suffice it to say, classes are nice and easy to define, it's a little trickier knowing where to define them...

In AS2.0, every class must be defined in an external .as file with exactly the same name as the class (ex. "GThing.as"). This class file is then placed inside of a "classPath", the most simple of which is just the same directory as the FLA using the class.

Once you have saved the .as file, you can create instances of it easily from within your FLA the same way you do in AS1:

myGThing = new GThing();
trace("I gotst some "+myGThing.canIGetSomeLove());

FlashMX 2004 sees the reference to the GThing class, and searches it's classPaths for a file called GThing.as. When it finds it, it imports it into the compiled SWF, and makes it available for creating instances.

Next time on AS the OOP turns... defining properties and methods with strong typing. Stay tuned.

Check out some basic OOP concepts in my Flash in the Can 2003 notes.

Posted @ 03:23 PM by Grant | TrackBack


Comments

mmmh ... thanx, but it's really just an introduction, i thought when i read your announcement last week that we'll got something strong to learn. :)

No problem, i just found 2 really good articles on http://www.person13.com/articles/

Good continuation, and i hope u'll give us some more next time :)

Posted by: petepx at September 10, 2003 06:27 AM

There's lots more to come... as I mentioned, this is serial content (ie. ongoing). I am a little bit limited in the amount of detail I can go into due to my contribution to FMX4 Demystified.

The publisher was nice enough to let me give away some info on my blog, but I can't give away the whole cake. :)

Still, I'm striving to make it useful for everyone as I continue. Suggestions are welcome.

Cheers.

Posted by: Grant Skinner at September 10, 2003 01:18 PM

I've translated this posting to korean.
thanks Grant!
here is the link.
http://feople.com/run/oo/view.php?id=crazymew&no=293

Posted by: Zooil at September 14, 2003 02:55 AM

This article have been translated in Latvian:
thnx to !ob
http://www.flash.lv/news/articles/article.php?id=9768

Posted by: darklow at September 17, 2003 03:12 PM

translated to spanish at http://blog.innocuo.com/index.php?p=22&more=1&c=1&tb=1&pb=1

Posted by: argonauta at September 20, 2003 01:59 AM

And to join all previous posters, I've translated the article into Dutch. Can be found over here: http://www.flashpro.nl/detail.asp?ID=133

Posted by: Flash.Pro at September 20, 2003 04:12 AM

This article is now available in german!

Check it out over here:
http://www.urbanspice.de/blog/archives/000002.html#more

Posted by: UrbanSpice at September 22, 2003 03:46 PM

Here's the link for the 1st article translated to brazilian portuguese: http://www.gabriellaet.com/blog/index.php?p=31&more=1&c=1

Thanks Grant!

Posted by: Gabriel Laet at September 23, 2003 03:10 PM

i can't follow the translated to spanish link posted by argonauta its a dead link. Would like this article, thanks

Posted by: Puerto Vallarta Fishing Charter at August 7, 2004 11:37 AM

my link didn't work either, maybe with a link in comments i could get that article argonauta.
thanks
http://www.fishpuertovallarta.com

Posted by: Puerto Vallarta Fishing Charter at August 7, 2004 11:41 AM

dfdsf

Posted by: fgfdg at October 14, 2004 06:30 PM

Hosting by NetKeepers.ca | Powered by Movable Type 2.661
The text content of this blog is licensed under a Creative Commons License. Graphics are ©2003 Grant Skinner.