AdvancED ActionScript 3.0_ Design Patter - Smith_ Ben.pdf
(
8432 KB
)
Pobierz
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
CONTENTS
Introduction
Design patterns are an abstract concept and a subject that involves being vague to help solve problems. This
is somewhat ambiguous and makes design patterns a difficult topic. Fortunately, a difficult subject does not
necessarily mean one that is complicated in its understanding. This will be evident in
AdvancED ActionScript
3.0: Design Patterns
.
This book requires prerequisite knowledge of ActionScript and Object Oriented Programming, but it
demonstrates the hand-in-hand relationship of OOP and design patterns. The beginning chapters of this
book discuss and detail OOP principles, and while some aspects may be review, all will be preparation for
upcoming chapters. Each chapter will prepare you for the next. Until Chapter 5 (the first review quiz), you will
be reinforcing your knowledge up to that point, as well as creating a foundation for your understanding of the
design pattern chapters. Chapters 6-8 thoroughly cover design patterns. Each pattern discussed is
demonstrated and explained with examples, real-life analogies, and answers to frequently asked
questions. Chapter 9 (the second review quiz of the book) again reinforces your knowledge up to that point.
Chapters 10-12 round out the book by covering the use of combining patterns and discuss how to remain
object-oriented in a fast-paced industry.
Welcome to
AdvancED ActionScript 3.0: Design Patterns
.
xiv
Chapter 1
Object-Oriented Programming
Object-oriented programming (OOP) is the practice of creating a software architecture that enables
flexibility through modular design. A programmer who is object-oriented isn’t necessarily one who is a
more advanced coder, but one who chooses to be a more strategic coder, and who adheres to the
principles of OOP. OOP isn’t a language; it’s the practice of architecting and the thought process behind it
that leads to applications and languages being object-oriented, such as ActionScript (AS) 3.0.
AS 3.0 was built as an object-oriented language to mirror the mental model of a programmer who knows
the benefits of breaking code into a series of objects that can message one another. But many who
choose to develop with AS 3.0 don’t use OOP. This is due to the somewhat daunting nature of OOP, as
well as the time required to learn it. AS 3.0 is meant to support the development of flexible architecture,
and using OOP can help prevent unmanageable code. Flexible architecture is easier to modify because
the objects that make up the application possess distinct boundaries, which simplifies substituting among
the objects you’re working with. Therefore, it’s beneficial to code with an object-oriented thought process.
However, that isn’t saying you can’t use AS 3.0 with a procedural programming mindset and be
successful.
Procedural programming, which is a linear method of developing, often culminates in lines of code that
have no separation of behaviors or train of thought. The language becomes nothing more than a series of
routines and subroutines. Procedural programming can work well if you’re the sole developer on a project,
because you’re familiar with your code. However, when more programmers are involved, it can be
cumbersome for them to become familiar with one another’s code and sift through the lines to see where a
change needs to be made. With OOP, each behavior in the application is contained in a unique class,
providing a more elegant way to view object collaborations. Because each unique class possesses a
name, it’s easy to track down; and because it should possess a single behavior, the class has only one
reason to ever change.
1
CHAPTER 1
The image in
Figure 1-1
is the result of the procedural code provided in
Listing 1-1
. The code uses an
image of my cat (Buttercup), and analyzes the pixel information to generate a halftone image.
Figure 1-1
. A color image of my cat Buttercup being converted to that of a halftone image
Listing 1-1
. The following code converts an image into that of a halftone
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
var img : BitmapData = new Buttercup( 1 , 1 );
var sampleSize : int = 4;
var brushSize : int = 4;
var pixelsTall : uint = img.height;
var pixelsWide : uint = img.width;
var rect : Rectangle = new Rectangle( 0 , 0 , sampleSize , sampleSize );
var totalBytesToScan : int = pixelsWide * pixelsTall;
var position : int = 0;
var offset : Number = sampleSize * .5;
var averageColor : uint;
var pixels : Vector.<uint > ;
var darks : Number;
var halftone : Shape = new Shape();
var scale : Number;
while ( position <= totalBytesToScan )
{
pixels = img.getVector( rect );
2
Plik z chomika:
superktos86
Inne pliki z tego folderu:
AdvancED ActionScript 3.0_ Design Patter - Smith_ Ben.pdf
(8432 KB)
AdvancED ActionScript 3.0_ Design Patter - Smith_ Ben.epub
(5480 KB)
cover.jpg
(55 KB)
metadata.opf
(4 KB)
Inne foldery tego chomika:
Zgłoś jeśli
naruszono regulamin