I’ve been programming in ActionScript for a while now even though I barely understand how extending classes exactly work. Most of my projects have been one-file scripts so you can probably imagine trying to work with a 1000+ line file (that’s probably too little for some of you :P).
Trying to look through numerous online tutorials have been daunting and or confusing at most, and don’t explain how extending actually works. Finding one that describes each essential keyword needed would be nice.
In past projects, I’ve managed to use two scripts, though not technically extending a class (I believe). For example:
Main.as (Main file)
package {
import flash.display.Sprite;
public class Main extends Sprite {
public function Main () {
trace(GLOBAL.version); // "1.0"
}
}
}
GLOBAL.as (a helper script in the same directory):
package {
public class GLOBAL {
public static var version:String = "1.0";
}
}
It appears that even though I hadn’t specifically imported the GLOBAL.as file, it’s still accessible.
What I’m asking from the SO community is: How can I better understand how extending a class works, using files in the same directory and another directory, Use the Main file as a simple “includer” and other files as helpers, such as adding a Sprite to the stage. Hopefully I’m not making this more difficult than it is. But for some reason I just can’t “get it”.
Other note: I’ve been working with JavaScript a lot more than I have ActionScript, so any guru’s out there wanting to give a tutorial on going from JavaScript to ActionScript would be a plus!
Id suggest looking at some object oriented tutorials in general. Ill give you my view of three elements of object orientation. Classes, extending and objects.
An object is an instance of something. An example of this could be two seperate people using the same system on two seperate computers. They are two seperate objects which are often referred to as instantiation. An object instantiates a class.
A class defines an object and provides ita functionality. An example of a class could be a database class for example which stores all of the connection details. The database class would need to be instantiated by the object in order to fullfill the requirements of the system, e.g. Insert a car make into the database.
Extending a class (more commonly known as class inheritance) actually inherits all of the functionality off the parent class. An example of this could be the database class (which i mentioned earlier) inheriting logic from a users table perhaps? When developing iPhone apps you often inherit specific framework functionality and ammend where necessary to make a bespoke system…
Hope this helps in some way.