Presentation: Introduction to Object Oriented Programming with ActionScript 3.0
Presenter: Scott Hutton, MindCross Training
Anything that will help build technical skills. I've seen ActionScript (but don't ask me to program in it without a book). Not quite sure I undertand Object Oriented programming. Should be interesting.....
Did some preliminary digging around in Captivate 3 before the session. It appears that all ActionScript programming needs to be through Flash. The actual flash objects are then imported into the Captivate file (usually buttons).
FYI - this session requires some preliminary knowledge of Flash and a little familiarity with ActionScript 3 OR Object Oriented programming. At least I have that much going for me.....
Again - my comments in italics, when I think about it.
Object-Oriented Programming (OOP) - technique oriented around objects and data.
- ActionScript 3 is object-oriented "capable"
+ Implementation of OO is optional.
- VB have object "tendencies" but not encouraging object methodology. ActionScript the same, but now more able to program using Object-oriented methodology.
Procedural vs. Object-Oriented
- Object Oriented - separates everything into objects. Hides the coding details within the individual objects.
+ Instead of spending time coding - spend time putting stuff together (not quite true - someone has to code stuff at some point).
+ Big difference - object-oriented is a technique. Reuseable. Is there something out there that allows you to do most of what you want?
- Procedural - concentrates on data and program functionality. Single-point(ish). The big long page of code in a file.
+Development done by using the timeline and all code contained within the flash file.
- Classes - a template/blueprint (a collection of data and events. But more fluid.)
+ Can use however you want, but you may not know how it exactly works.
+ Goes through a lot of trouble to hide code. (see below)
- Encapsulation - Hiding the details of the class
- Inheritance and Composition - Aids in the reuse of code
+ Inheritance - I can take stuff and override it
+ Composition - Collection of things in one place that can be reused together
- Polymorphism (Overloading, overriding)
+ An entity that exists in multiple forms, and entity having different behaviors
+ Provides flexibility
+ Coded one way, but it doesn't do what I want (i.e. Area - triangle. I want to calculate the area of a circle).
The non-coder parts of Flash promotes this approach.
The Class is the foundation of object-oriented programming
- Blueprint comprised of
- Coding methodology
+ An object is an INSTANCE of a class
- Promotes maintainability and reusability (Why Classes and Object-Oriented programming important!!!)
+ If someone in an organization creates a class, other people can use it and make minor changes (if needed) so they can use. Or can use wholesale.
+ Much easier to create programs using a whole bunch of pieces than coding from scratch.
Classes v. Objects
- An object is an instance of a class.
+ Instantiation - my object can use an individual use of a class. Example - a Continue button that you can't change but you can use. Each instance of that continue button is an object.
+ Can build a class - such as a background template.
Flash will give you the instance names. (remember dropping and dragging items already available in Flash?). You can also change the instance names.
- When you customize - you are customizing the particular instance (object). You are NOT customizing the actual button (class).
- You may only be able to customize pieces of that button (the color, the height/width, the name on the button). May not be able to customize how that button works. This helps when trying to figure out why your instance of the button doesn't work right.
ActionScript command: package - a declarative function required in a Class. If ActionScript file and flash file in same directory, can be blank.
If ActionScript file and flash file is in sub-directories, I have to use package to define where the information is.
- package Classes - Classes points to an import command. In this instance, the ActionScript file is one level down from the Flash file (wish I had pictures to show you this.....)
+ within the flash file - import Classes.Glossary
+ Also a setting in flash called Classpath where all of your Classes are.
ActionScript command: public - allows you to tell program what you can use
public var - anyone can control the variable (not a good idea. Folks can change data on you).
public function - anyone can control the methods. Most often - methods available, variables private.
Remember - all about sharability with how you organize your work.
- Hides the details of the code and data
+ The developer decides what will be exposed to the user (public vs. private)
- Primary benefits
+ information hiding
- Object design
+ Think about what will be made public vs. private
Access modifiers within ActionScript
- public (see above) - you trust that it will work
- private - not sure it works or how you want to work. Can't touch. Only seeable by methods of the class (within the code). Still USED by the class. End user doesn't see it.
- The ability to inherit properties and methods from another class
+ Extends the functionality
+ Copy + paste code much nicer than rebuilding from scratch
- Classes are organized into a tree structure
+ A subclass includes ALL of the functionality of a higher level class
+ Everything from a higher level class is automatically applicable to lower levels in the hierarchy
- Class hierarchy
+ Classes can be created from other classes. (Copy + modify code)
(Again - wish I had picture. Shows how classes work within Flash.)
Example - Flash MovieClip class (one of the things you drag and drop into your stage)
- Package flash.display
- Class - public dynamic class MovieClip
MovieClip (below are all of the classes the class MovieClip inherited)
- Event EventDispatcher
- Subclasses - LivePreview Parent
- Inheritance - you are part of a tree. Add to it, extend capabilities, pass it on. Is a... (RaceCar is a vehicle)
- Composition is a group of classes that are used together. Has a... (Vehicle has a tire)
Remember - any class can be extended
Example3.as (the actionscript file)
public class Example3 extends MovieClip
(Example3.fla - var myObject:Example3 = new Example3();)
Must have import and extends in the code to extend the capability of the class.
Since opening up your variables is a really bad idea, need a method to return the variable so it can be seen.
(Not gonna type the code - really have to take a look at the presentation files. Essentially, the variable is private. The function is public that returns the variable.)
(from here, I get confused..... I'll admit - I'm not entirely certain how I would use these techniques. The presenter had to race through this section because he ran out of time.)
- The same method name may be implemented in different classes.
- Example - the x and y properties are referenced the same way regardless of which class they are part of (button, movie clip, etc).
+ a button may have an x value of 10 and a y value of 20
+ a movie clip may have an x value of 400 and a y value of 500
- Methods used when an instance of a class is created
- Must have the same name of the class (see the code)