Thursday, August 4, 2011

OOP

Knowing when to opt for an object-oriented model depends largely on
understanding the benefits of OOP, among them:

Classes. Classes are collections of related functions and variables gathered
to facilitate one or more specific goals. They are the foundation of
OOP, and we’ll look at a few ways to use them.

Inheritance. Inheritance is one of OOP’s greatest sources of power, as it
allows you to add functionality to an existing feature set without reinventing
the wheel, as the saying goes. Being able to extend an existing class to
create a subclass, rather than originating an entirely new class, can save
you a significant amount of time and labor, as well as improve project
design.

Composition. Inheritance isn’t appropriate for every situation, and composition
is often a useful alternative. Composition is a technique somewhat
akin to collecting related classes, much like classes collect related
functions and variables. The classes do not inherit characteristics from
one another, but are made to work together in productive ways.


Encapsulation. It’s usually not a good idea to expose all aspects of a class
to other classes or the surrounding application. Encapsulation isolates
most elements of a class from the outside world, allowing only a select
few elements, if any, to be seen by structures that use the class.

Polymorphism. Polymorphism allows objects of different classes to have,
through a unified interface design, methods that have the same name but
that behave differently when invoked. By using polymorphism, you can
reduce the number of methods that must be documented and learned,
and, more importantly, make it easier to extend classes. New subclasses
can use an existing method name but return a result appropriate to the
new class.


To get started you open: 
ActionScript Class.
You name it with a capital letter.
For example: Main
Save it.

Next you open a regular action script file.
Save it in the same folder as your Main.as
Then in the properties panel you give it a class of Main.



For a document class you have to give it a timeline. 



package  {
    import flash.display.MovieClip;
   
    public class Main  extends MovieClip {  //you dont have to extend from something, but we are using a document class.
                                              //you have to extend a mc with the document class because we need a timeline
                                            //if you were making a sprite for example you do need a timeline

        public function Main() {
            // constructor code
          
            trace("hello world");
                
        }

    }


And then a bunch of shit happened that I should probably have notes on.
 

No comments:

Post a Comment