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:
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:
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.
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.
Comments (12)
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 AMURL:
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 PMURL: http://gskinner.com/
I've translated this posting to korean.
Posted by: Zooil at September 14, 2003 02:55 AMthanks Grant!
here is the link.
http://feople.com/run/oo/view.php?id=crazymew&no=293
URL: http://feople.com
This article have been translated in Latvian:
Posted by: darklow at September 17, 2003 03:12 PMthnx to !ob
http://www.flash.lv/news/articles/article.php?id=9768
URL:
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 AMURL: http://blog.innocuo.com
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 AMURL: http://www.flashpro.nl
This article is now available in german!
Check it out over here:
Posted by: UrbanSpice at September 22, 2003 03:46 PMhttp://www.urbanspice.de/blog/archives/000002.html#more
URL: http://www.urbanspice.de
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 PMURL: http://www.gabriellaet.com/blog/
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 AMURL: http://www.fishpuertovallarta.com
my link didn't work either, maybe with a link in comments i could get that article argonauta.
Posted by: Puerto Vallarta Fishing Charter at August 7, 2004 11:41 AMthanks
http://www.fishpuertovallarta.com
URL: http://www.fishpuertovallarta.com
dfdsf
Posted by: fgfdg at October 14, 2004 06:30 PMURL: http://dfdfds
i want to switch my link to espano but cant figure it out?
Posted by: Sean at December 30, 2006 02:17 AMURL: http://www.puertovallartafish.com