Tải bản đầy đủ

OReilly essential actionscript 2 0 jun 2004 ISBN 0596006527










TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

EssentialActionScript2.0
ByColinMoock

Publisher :O'Reilly
PubDate :June2004

ISBN :0-596-00652-7
Pages :544


InEssentialActionScript2.0,bestselling
authorColinMoockcoverseverythingyou'll
needtoknowaboutthenewActionScript
languageanditsmethodologies.Experienced
Flashdevelopersandprogrammerscoming
fromotherlanguageswillenjoythesheer
depthofMoocks'scoverage.Novice
programmerswillappreciatethefrequent,
low-jargonexplanationsthatareoften


glossedoverbyadvancedprogramming
books.EssentialActionScript2.0istheone
bookeveryActionScriptcodermustown.











TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

EssentialActionScript2.0
ByColinMoock

Publisher :O'Reilly
PubDate :June2004
ISBN :0-596-00652-7
Pages :544



Copyright

Foreword

Preface
ThisBookWantsYou

WhatThisBookIsNot




WhoShould(andShouldn't)ReadThisBook




DecipheringFlashVersions




TypographicalConventions




We'dLiketoHearfromYou



ActionScript2.0VersusActionScript1.0
ExampleFilesandResources
UsingCodeExamples
Acknowledgments
PartI:TheActionScript2.0Language
Chapter1.ActionScript2.0Overview






Section1.1.ActionScript2.0Features




Section1.3.FlashMX2004Version2Components




Section1.5.Let'sGoOOP

Section1.2.FeaturesIntroducedbyFlashPlayer7
Section1.4.ActionScript1.0and2.0inFlashPlayer6and7
Chapter2.Object-OrientedActionScript




Section2.1.ProceduralProgrammingandObject-OrientedProgramming




Section2.3.ButHowDoIApplyOOP?




Section2.2.KeyObject-OrientedProgrammingConcepts
Section2.4.OnwiththeShow!
Chapter3.DatatypesandTypeChecking
Section3.1.WhyStaticTyping?




Section3.2.TypeSyntax




Section3.4.Built-inDynamicClasses




Section3.6.Casting




Section3.8.ActionScript2.0TypeCheckingGotchas




Section3.3.CompatibleTypes
Section3.5.CircumventingTypeChecking
Section3.7.DatatypeInformationforBuilt-inClasses
Section3.9.UpNext:CreatingClassesYourOwnDatatypes!
Chapter4.Classes
Section4.1.DefiningClasses




Section4.2.ConstructorFunctions(Take1)




Section4.4.Methods




Section4.6.CompletingtheBoxClass




Section4.3.Properties
Section4.5.ConstructorFunctions(Take2)
Section4.7.PuttingTheoryintoPractice
Chapter5.AuthoringanActionScript2.0Class
Section5.1.ClassAuthoringQuickStart




Section5.2.DesigningtheImageViewerClass




Section5.4.UsingImageViewerinaMovie




Section5.6.ImageViewerImplementation(Take3)



Section5.3.ImageViewerImplementation(Take1)
Section5.5.ImageViewerImplementation(Take2)
Section5.7.BacktotheClassroom
Chapter6.Inheritance




Section6.1.APrimeronInheritance



Section6.2.SubclassesasSubtypes




Section6.3.AnOOPChatExample




Section6.5.ConstructorFunctionsinSubclasses




Section6.7.AugmentingBuilt-inClassesandObjects




Section6.9.AbstractandFinalClassesNotSupported

Section6.4.OverridingMethodsandProperties
Section6.6.SubclassingBuilt-inClasses
Section6.8.TheTheoryofInheritance
Section6.10.Let'sTryInheritance




Chapter7.AuthoringanActionScript2.0Subclass




Section7.2.TheImageViewerDeluxeSkeleton




Section7.4.AutosizingtheImageViewer




Section7.6.MovingRightAlong

Section7.1.ExtendingImageViewer'sCapabilities
Section7.3.AddingsetPosition()andsetSize()Methods
Section7.5.UsingImageViewerDeluxe
Chapter8.Interfaces




Section8.1.TheCaseforInterfaces




Section8.3.InterfaceSyntaxandUse




Section8.5.UpNext,Packages

Section8.2.InterfacesandMultidatatypeClasses
Section8.4.MultipleTypeInheritancewithInterfaces
Chapter9.Packages




Section9.1.PackageSyntax




Section9.3.PackageAccessandtheClasspath




Section9.5.JustaLittleMoreTheory

Section9.2.DefiningPackages
Section9.4.SimulatingPackagesinActionScript1.0
Chapter10.Exceptions




Section10.1.TheException-HandlingCycle




Section10.3.ExceptionBubbling




Section10.5.NestedExceptions




Section10.7.LimitationsofExceptionHandlinginActionScript2.0

Section10.2.HandlingMultipleTypesofExceptions
Section10.4.ThefinallyBlock
Section10.6.ControlFlowChangesintry/catch/finally
Section10.8.FromConceptstoCode





PartII:ApplicationDevelopment
Chapter11.AnOOPApplicationFramework



Section11.1.TheBasicDirectoryStructure




Section11.2.TheFlashDocument(.flafile)




Section11.4.TheDocumentTimeline




Section11.6.ProjectsinFlashMXProfessional2004




Section11.3.TheClasses
Section11.5.TheExportedFlashMovie(.swffile)
Section11.7.Let'sSeeItinAction!
Chapter12.UsingComponentswithActionScript2.0
Section12.1.CurrencyConverterApplicationOverview




Section12.2.PreparingtheFlashDocument




Section12.4.HandlingComponentEvents




Section12.3.TheCurrencyConverterClass
Section12.5.ComponentsComplete
Chapter13.MovieClipSubclasses
Section13.1.TheDualityofMovieClipSubclasses




Section13.2.Avatar:AMovieClipSubclassExample




Section13.4.IssueswithNestedAssets




Section13.6.CuriouserandCuriouser




Section13.3.Avatar:TheCompositionVersion
Section13.5.ANoteonMovieClipSub-subclasses
Chapter14.DistributingClassLibraries
Section14.1.SharingClassSourceFiles
Section14.2.SharingClassesWithoutSharingSourceFiles

Section14.3.SolvingRealOOPProblems


PartIII:DesignPatternExamplesinActionScript2.0
Chapter15.IntroductiontoDesignPatterns




Section15.1.BringonthePatterns
Chapter16.TheObserverDesignPattern




Section16.1.ImplementingObserverinActionScript2.0




Section16.3.MemoryManagementIssueswithObserver






Section16.2.Logger:ACompleteObserverExample
Section16.4.BeyondObserver
Chapter17.TheSingletonDesignPattern
Section17.1.ImplementingSingletoninActionScript2.0
Section17.2.TheSingletonPatternintheLoggerClass
Section17.3.SingletonVersusClassMethodsandClassProperties




Section17.4.AWarningAgainstSingletonsasGlobals



Section17.5.OntoUserInterfaces



Chapter18.TheModel-View-ControllerDesignPattern



Section18.1.TheGeneralArchitectureofMVC




Section18.2.AGeneralizedMVCImplementation




Section18.4.FurtherExploration

Section18.3.AnMVCClock
Chapter19.TheDelegationEventModel




Section19.1.StructureandParticipants




Section19.3.CoreImplementation




Section19.5.OtherEventArchitecturesinActionScript

Section19.2.TheFlowofLogic
Section19.4.NightSky:ADelegationEventModelExample
Section19.6.FromSomePlacetoSomeOtherPlace


PartIV:Appendixes
AppendixA.ActionScript2.0LanguageQuickReference

SectionA.1.GlobalProperties






SectionA.2.GlobalFunctions
AppendixB.DifferencesfromECMAScriptEdition4
Colophon
Index


Copyright©2004O'ReillyMedia,Inc.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles(http://safari.oreilly.com).Formoreinformation,
contactourcorporate/institutionalsalesdepartment:(800)
998-9938orcorporate@oreilly.com.
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
EssentialActionScript2.0,theimageofacoralsnake,and
relatedtradedressaretrademarksofO'ReillyMedia,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.


Foreword
IcametoMacromediainthesummerof2000,shortlyafter
graduatingfromcollege,tostartworkingasasoftwareengineer
ontheFlashteam.Inmyfirstdaysatthecompany,theteam
wasworkingtirelesslytoshipFlash5,andeveryonewastoo
busytogivememuchworktodo,letaloneguidemeinthe
waysofMacromediacorporatelife.LittledidIrealizethatasI
waslearningmywayaroundthecomplexC++architectureof
theFlashauthoringtool,ActionScriptwasalsobeginningits
owncareerinthewebdevelopmentindustry.Flash5wasa
landmarkreleasefortheFlashauthoringtool:itbrought
ActionScriptfromaninterfacethatrequiredpoint-and-click
interactiontoafull-fledgedscriptinglanguagebasedonthe
ECMAScriptstandard,witharealtexteditor.Iarrivedjustas
theFlashteamwasputtingrealscriptingpowerinthehandsof
Flashdevelopers.OverthenexttworeleasesofFlash,I
participatedinthecontinuationofthateffort,firstbyproducing
theActionScriptdebuggerinFlashMXand,mostrecently,by
developingtheActionScript2.0compiler.Mypastfewyearsare
inextricablylinkedtothislanguage,andithascontributedto
mygrowth,justasIhavecontributedtoitsgrowth.
Inthebeginning,myfeelingsaboutActionScriptweresimilarto
thefeelingsalotoftraditionaldevelopershavewhencomingto
thelanguage.Ifoundmyselfcomfortablewithitsflexibility,yet
frustratedwithitslimitations.Iwashappytobringfeatures
suchasthedebuggertolife,becauseithelpedFlashmeetmy
ownexpectationsofaprogrammingenvironment.Ienjoyed
workingtoclosethegapsinFlash'scapabilities,featureby
feature.WithFlashMX,wemadestridesbygreatlyimproving
thecodeeditorandbyenablinguserstodebugtheir
ActionScript.However,ActionScript1.0stillhadonefrustrating
limitationthatwedidnotaddressinFlashMX:itwaspossible
towritecodethatemployedobject-orientedprogramming


(OOP)techniques,butdoingsowascomplexandunintuitive
andnotwellintegratedwithFlashconceptslikelibrarysymbols.
WithFlashMX2004andActionScript2.0,wehavearrivedat
yetanothermajorlandmarkinActionScript'sevolution.
ActionScript2.0offersamoresophisticatedsyntaxfortheOOP
constructsthatActionScripthasalwayssupported.ActionScript
2.0iseasiertolearnthanitspredecessor,anditiscloserto
otherindustry-standardprogramminglanguages,suchasJava
andC#.Itgivesdeveloperstheframeworkneededtobuildand
maintainlarge,complexapplications.Inaddition,our
implementationrequiredminimalchangestotheFlashPlayer,
meaningthatActionScript2.0canbeexportedtoFlashPlayer
6,whichwasalreadynearlyubiquitousatthetimeofFlashMX
2004'srelease.
IntheshorttimethatActionScripthasbeenaround,developers
havefoundittobeextraordinarilypowerful.Flashplacesfew
constraintsonthedeveloper'saccesstotheMovieCliphierarchy
andobjectmodel,permittingthemtodoanything,anywhere.
Thisflexibilityhasstirredthecreativityofourusers,enabling
themtogrowintoActionScriptandexperimentwithit.However,
thelackofstructureinActionScript1.0madeapplications
difficulttoscaleup,leadingtounwieldyprojectsthatteams
foundchallengingtomaintainandorganize.Itwastooeasyto
writepoorcode,nottomentionplacecodeinlocationsalmost
impossibletofindbyothersunfamiliarwiththeproject.
ActionScript2.0aspirestoaddressthesepitfallsbyencouraging
astructurethatalldeveloperscanadheretoandunderstand.
Moreover,theActionScript2.0compilerprovidesdevelopers
withfeedbackonerrorsthatotherwisewouldn'tbefounduntil
theymanifestedasbugsatruntime.Still,ActionScriptcontinues
toprovideextensiveanduniquecontrolovergraphical
elements.WestrovetoensurethatActionScriptisapowerful
languagemovingforward,withouttreadingonthetoesof
already-seasonedscripters.
ActionScript2.0wasalsothebasisforseveralothernotable


elementsofFlashMX2004.
ThefollowingareallwritteninActionScript2.0:
Thesecondgenerationofcomponents(i.e.,thev2
components)
ThenewScreensmetaphor,whichincludesSlidesand
Forms(availableonlyinFlashMXProfessional2004)
Thesophisticateddataintegrationcapabilities
ThemultilingualresourcesupportofferedbytheStrings
panel
Buildingsignificant,large-scalefeaturesusingActionScript2.0
providedvaluabletestingandvalidationtothoseofusworking
onthecompilerandinformedmanyofourdesigndecisions.
Moreimportantly,thesefeaturesgiveFlashdevelopers
comprehensive,workingexamplesofActionScript2.0inaction
(seetheMacromedia/FlashMX2004/en/FirstRun/Classesfolder
underyourapplication'sinstallationfolder).Likewise,the
benefitsofActionScript2.0arereadilyapparentinthese
features,whichallconsistofclassesthatarewellorganizedin
themx.*classhierarchy.Inaddition,itiseasierthaneverto
determinewhichcodecorrespondstothedifferentcomponents,
asActionScript2.0hasmadeitpossibletoeliminate
troublesomerelicsofActionScript'spast,suchasthe#initclip
pragma(compilerdirective).
ActionScriptstartedlifeasafewscriptingcommandsinserted
bymouseclicks.Fiveyearslater,itisafull-featuredobjectorientedlanguagewithwhichlarge,complexapplicationscan
bedeveloped.Furthermore,itpresentsaclean,simplesyntax
thatiseasytoreadandstraightforwardforabeginnertopick
up.InmytworeleasesoftheFlashauthoringtool,Ihave


learnedmoreandmoreaboutActionScripteachstepofthe
way,andnowIamproudtohavehelpedredefineit.Colin
Moock'spreviousbook,ActionScriptforFlashMX:TheDefinitive
Guide,wasindispensabletome,evenasI'veworkedonthe
newfaceofActionScript.Itisthesinglebookyou'llfindwithin
easyreachatthedeskofeveryengineerontheFlashteam.
Manyofourengineersherewerealreadylookingforwardtothis
newbook,EssentialActionScript2.0,beforeitshipped.And
withgoodreason.Inthisvolume,Moockhasonceagainapplied
hisinsightful,conversationalstyletocomplextopics,teaching
notonlythesyntaxofActionScript2.0butalsothetheoryand
principlesofOOP.Hehasthoroughlyresearchedthe
relationshipsbetweenActionScript2.0,itspredecessor,and
otherlanguages,andheillustratestheirdifferencesinprecise
detail.Moock'sintimatefamiliaritywithFlashandActionScriptis
evidentinthisinstructiveandapproachabletext,which
certainlyisanessentialcompanionforanyonewishingtolearn
andmastertheActionScript2.0language.
RebeccaSun
SeniorSoftwareEngineer
MacromediaFlashTeam
March2004


Preface
InSeptember2003,MacromediareleasedFlashMX2004,and,
withit,ActionScript2.0adrasticallyenhancedversionofFlash's
programminglanguage.
ActionScript2.0introducesaformalobject-oriented
programming(OOP)syntaxandmethodologyforcreatingFlash
applications.Comparedtotraditionaltimeline-based
developmenttechniques,ActionScript2.0'sOOP-based
developmenttechniquestypicallymakeapplications:
Morenaturaltoplanandconceptualize
Morestableandbug-free
Morereusableacrossprojects
Easiertomaintain,change,andexpandon
Easiertotest
Easiertocodevelopwithtwoormoreprogrammers
Thosearesomeextraordinaryqualities.Soextraordinary,in
fact,thatthey'veturnedthisbookintosomethingofazealot.
ThisbookwantsyoutoembraceActionScript2.0witha
passion.


ThisBookWantsYou
Thisbookwantsyoutouseobject-orientedprogrammingin
yourdailyFlashwork.Itwantsyoutoreapthebenefitsof
OOPoneofthemostimportantrevolutionsinprogramming
history.ItwantsyoutounderstandActionScript2.0completely.
Anditwillstopatnothingtogetwhatitwants.
Here'sitsplan...
First,inPartI,TheActionScript2.0Language,thisbook
teachesyouthefundamentalsofobject-orientedconcepts,
syntax,andusage.Evenifyouhavenevertriedobject-oriented
programmingbefore,PartIwillhaveyouunderstandingand
applyingit.Chapter1givesanoverviewofActionScript2.0.
Chapter2teachesyouthebasicsofOOPandhelpsyoudecide
howmuchisrightforyourprojects.Chapter3throughChapter
10offerdetailsonclasses,objects,methods,properties,
inheritance,composition,interfaces,packages,andmyriad
othercoreOOPconcepts.IfyoualreadyknowalotaboutOOP
becauseyouprograminJavaoranotherobject-oriented
language,thisbookhelpsyouleveragethatpriorexperience.It
drawsabundantcomparisonsbetweenFlash-basedOOPand
whatyoualreadyknow.Alongtheway,itintroducesOOPinto
yourregularroutinethroughexercisesthatdemonstraterealworldFlashOOPinaction.
InPartII,ApplicationDevelopment,thisbookteachesyouhow
tostructureentireapplicationswithActionScript2.0.InChapter
11,you'lllearnbestpracticesforsettingupandarchitectingan
object-orientedproject.InChapter12andChapter13,you'll
learnhowuserinterfacecomponentsandmovieclipsfitintoa
well-structuredFlashapplication.InChapter14,you'llseehow
toparcelupandsharecodewithotherdevelopers.Allthiswill
helpyoubuildmorescalable,extensible,stableapps.It'sall
partofthisbook'splan.


Finally,inPartIII,DesignPatternExamplesinActionScript2.0,
you'llexploreavarietyofapproachestovariousprogramming
situations.You'llseehowtoapplyprovenandwidelyaccepted
object-orientedprogrammingstrategiesknownasdesign
patternstoFlash.ThedesignpatternsinPartIIIcovertwokey
topicsinFlashdevelopment:eventbroadcastinganduser
interfacemanagement.Afteranintroductiontodesignpatterns
inChapter15,we'llexplorefourcommonpatternsinChapter
16throughChapter19.Onceyou'vetriedworkingwiththe
patternspresentedinPartIII,you'llhaveconfidenceconsulting
thelargerbodyofpatternsavailableonlineandinother
literature.Andyou'llhavetheskillstodrawonotherwidely
recognizedobject-orientedpractices.Yousee,thisbookknows
itwon'tbewithyouforever.Itknowsitmustteachyoutofind
yourownsolutions.
Thisbookdoesn'tcarewhetheryoualreadyknowthemeaning
ofthewords"class,""inheritance,""method,""prototype,"or
"property."IfyouhavenoideawhatOOPisorwhyit's
worthwhile,thisbookisdelightedtomeetyou.If,ontheother
hand,you'realreadyaskilledobject-orienteddeveloper,this
bookwantstomakeyoubetter.Itwantsyoutohavethe
exhaustivereferencematerialandexamplesyouneedto
maximizeyourproductivityinActionScript2.0.
Thisbookisdeterminedtomakeyouanadeptobject-oriented
programmer.Andit'sconfidentitwillsucceed.


WhatThisBookIsNot
WhilethisbookiszealousaboutcoreActionScript2.0and
object-orientedprogramming,itdoesnotcovereverypossible
ActionScript-relatedtopic.Specifically,youwon'tfindmuch
discussionofcompaniontechnologies,suchasFlashRemoting
orFlashCommunicationServer,norwillyoufindadictionarystyleLanguageReference,asyoudoinActionScriptforFlash
MX:TheDefinitiveGuide(O'Reilly).Whereasthatbook
describestheFlashPlayer'snativefunctions,properties,
classes,andobjects,thisbookteachesyouhowtousethose
classesandobjects,andhowtofitthemintoyourowncustombuiltstructures.Thebuilt-inlibraryofclassesavailableinthe
FlashPlayerchangedonlyincrementallyinFlashPlayer7,so
ActionScriptforFlashMX:TheDefinitiveGuide,continuestobe
aworthwhilereferenceeventoActionScript2.0developers.It
makestheperfectcompaniontoEssentialActionScript2.0.
ThisbookdoesnotcovertheScreensfeature(includingSlides
andForms),whichissupportedonlyinFlashMXProfessional
2004.Screensareusedtodevelopuserinterfacesvisually(in
thetraditionofMicrosoftVisualBasic)andtocreateslideshow
presentations(inthetraditionofMicrosoftPowerPoint).
Althoughthefeatureisnotadirecttopicofstudy,you'll
certainlybepreparedtoexploreScreensonyourownonceyou
understandthefundamentalstaughtbythistext.
Thisbookisalsonotaprimeronprogrammingbasics,suchas
conditionals(ifstatements),loops,variables,arrays,and
functions.Foragentleintroductiontoprogrammingbasicsin
Flash,againseeActionScriptforFlashMX:TheDefinitiveGuide.
Finally,thisbookdoesnotteachtheuseoftheFlashauthoring
tool,exceptasitappliestoapplicationdevelopmentwith
ActionScript2.0.Forhelpwiththeauthoringtool,suchas
creatinggraphicsortimelineanimations,youshouldconsultthe


in-productdocumentationoranyofthefinethird-partybooks
availableonthetopic,includingO'Reilly'sownFlashOutofthe
Box,byRobertHoekman,scheduledforreleaseinthesecond
halfof2004.


WhoShould(andShouldn't)ReadThisBook
Youshouldreadthisbookifyouare:
AnintermediateActionScript1.0orJavaScriptprogrammer
whounderstandsthebasicsofvariables,loops,
conditionals,functions,arrays,andotherprogramming
fundamentals.
AnadvancedActionScript1.0orActionScript2.0
programmerwhowantshardfactsaboutbestpracticesfor
OOPinActionScript2.0,includingdetailedsyntaxand
usageinformation,languageidiosyncrasies,andsample
applicationstructures.
AFlashdesignerwhodoessomeprogrammingandis
curioustolearnmoreaboutapplicationdevelopment.
AprogrammermigratingtoFlashdevelopmentfrom
anotherlanguage,suchasJava,C++,Perl,JavaScript,or
ASP.(BepreparedtolearnthefundamentalsoftheFlash
authoringtoolfromthesourcesmentionedearlier.You
shouldalsoreadChapter13,MovieClips,inActionScriptfor
FlashMX:TheDefinitiveGuide,availableonlineat:
http://moock.org/asdg/samples.)
YoushouldnotreadthisbookifyouareaFlash
designer/animatorwithlittleornoprogrammingexperience.
(StartyourstudyofActionScriptwithActionScriptforFlashMX:
TheDefinitiveGuideinstead.)


ActionScript2.0VersusActionScript1.0
Chapter1introducesActionScript2.0inmoredetail,butthis
discussionprovidesabrieforientationforActionScript1.0
developers.
ActionScript1.0andActionScript2.0havethesamecore
syntax.Basicslikeconditionals,loops,operators,andother
non-object-orientedaspectsofActionScript1.0canbeused
verbatiminActionScript2.0andarestillanofficialpartofthe
language.Inaddition,objectcreation,propertyaccess,and
methodinvocationhavethesamesyntaxinActionScript1.0
andActionScript2.0.So,generallyspeaking,ActionScript2.0is
familiartoActionScript1.0developers.Themaindifference
betweenthetwoversionsofthelanguageisobject-oriented
syntaxandauthoringtoolsupportforobject-oriented
development.
InActionScript1.0,object-orientedprogramminghadan
unintuitivesyntaxandnearlynoauthoringtoolsupport(e.g.,no
compilermessages,noclassfilestructure,notypechecking,
poorconnectionsbetweencodeandmovieassets,etc.).With
ActionScript1.0,object-orientedprogrammingwasan
awkward,esotericundertaking.WithActionScript2.0,itisa
naturalendeavor.ActionScript2.0'smoretraditionalOOP
implementationmakesActionScript2.0skillsmoretransferable
toandfromotherlanguages.
Ifyou'reanActionScript1.0programmerandhavealready
beenapplyingOOPtechniques,ActionScript2.0willbeadelight
(andarelief)toworkwith.Ifyou'reanActionScript1.0
programmerwhodoesn'tuseOOP,youdon'tneedtolearnOOP
inActionScript1.0beforeyoulearnitinActionScript2.0.Now
istheperfecttimetoexploreandadoptthisimportant
methodology.OOPofferstoincreaseyourproductivity,make
yourprojectseasiertomanage,andimproveyourcode's


qualityandreusability.
Althoughthisbookdoesn'tspendalotoftimefocusingonhow
toupgradeyourcodefromActionScript1.0toActionScript2.0,
afterreadingit,youshouldhavenotroubledoingso.Thebook
focusesongivingyouastrongfundamentalunderstandingof
ActionScript2.0andIdidn'twanttounnecessarilydistractfrom
thatfocusbytalkingtoomuchaboutobsoleteActionScript1.0
code.Thatsaid,keepaneyeoutforthenumerousActionScript
1.0notesthatlooklikethis:

SuchnotesdirectlycompareanActionScript1.0
techniquewiththeanalogousActionScript2.0technique,
soyoucanseethedifferencebetweentheoldwayof
doingthingsandthenew,improvedway.
Finallylet'sbeclearaboutwhatImeanby"programmingin
ActionScript2.0versusActionScript1.0."Ifyouarejust
creatingtimelinecodeandnotusingActionScript2.0classes,
staticdatatypes,orotherOOPfeatures,thenitisreallymoot
whetheryourefertoyourcodeas"ActionScript1.0"or
"ActionScript2.0."WithoutusingOOPfeatures,ActionScript2.0
codelooksindistinguishablefromActionScript1.0code.So
whenIsay,"we'regoingtolearntoprograminActionScript
2.0,"ofnecessity,I'massumingyou'recreatingameaningful
OOPapplicationinwhichyou'redevelopingoneormoreclasses.
Foranexample,consideranonlineformthatmerelysendsan
email.YoumightimplementthatformentirelyontheFlash
timelineusingonlyvariablesandfunctions.Ifthat'sgenerally
allyouwanttodowithyourapplications,thenfrankly,thisbook
mightbeoverkillforyourcurrentneeds.However,giventhe
chance,thisbookwillexpandyourhorizonsandteachyouhow
tobeaskilledobject-orientedprogrammerandtotacklelarger
projects.SowhenIsay"programminginActionScript2.0,"I
mean"developingobject-orientedapplicationsinActionScript


2.0."Theemphasisison"object-orienteddevelopment"rather
thanActionScript2.0,perse,asActionScript2.0isjusta
meanstothatend.Youmayask,"Isthisbookabout
ActionScript2.0syntax,object-orienteddesign,orobjectorientedprogramming?"Theansweris,"Alloftheabove."
FormoreinformationaboutActionScript2.0andActionScript
1.0inrelationtoFlashPlayer6andFlashPlayer7,seeChapter
1.


DecipheringFlashVersions
WiththeintroductionoftheStudioMXfamilyofproducts,
includingFlashMX,Macromediaabandonedastandardnumeric
versioningsystemforitsFlashauthoringtool.Subsequentto
FlashMX,Macromediaincorporatedtheyearofreleaseinthe
productname(productsreleasedafterSeptemberusethe
followingyearintheproductname).Withthe2004release,
MacromediaalsosplittheFlashauthoringtoolintotwo
versions:FlashMX2004andFlashMXProfessional2004,as
discussedinTableP-1.Theprincipalfeaturesspecifictothe
Professionaleditionare:
Screens(form-andslide-basedcontentdevelopment)
Additionalvideotools
Projectandassetmanagementtools
Anexternalscripteditor
Databinding(linkingcomponentstodatasourcesobtained
viawebservices,XML,orrecordsets)
Advancedcomponents(however,FlashMXProfessional
2004componentsworkhappilyinFlashMX2004)
Mobiledevicedevelopmenttools
ThetechniquestaughtinthisbookcanbeusedinbothFlash
MX2004andFlashMXProfessional2004,althoughInotethe
rarecircumstancesinwhichthetwoversionsdifferas
pertainingtodevelopmentinActionScript2.0.UnliketheFlash


authoringtool,theFlashPlayerisstillversionednumerically;at
presstime,thelatestversionisFlashPlayer7.TableP-1
describesthenamingconventionsusedinthisbookforFlash
versions.
TableP-1.Flashnamingconventionsusedinthisbook
Name

Meaning

FlashMX

TheversionoftheFlashauthoringtoolthatwasreleasedatthesametimeas
FlashPlayer6.

FlashMX
2004

ThestandardeditionoftheFlashauthoringtoolthatwasreleasedatthesame
timeasFlashPlayer7.Inthegeneralsense,theterm"FlashMX2004"isused
torefertoboththestandardedition(FlashMX2004)andtheProfessional
edition(FlashMXProfessional2004)ofthesoftware.Whendiscussinga
featurethatislimitedtotheProfessionaledition,thistextstatesthelimitation
explicitly.

TheProfessionaleditionoftheFlashauthoringtoolthatwasreleasedatthe
FlashMX
sametimeasFlashPlayer7.TheProfessionaleditionincludessomefeatures
Professional
notfoundinthestandardedition(seeprecedinglist).TheProfessionaledition
2004
isnotrequiredforthisbookortouseActionScript2.0.
TheFlashPlayer,version7.TheFlashPlayerisabrowserpluginformajorweb
browsersonWindowsandMacintosh.Atpresstime,FlashPlayer6,butnot
FlashPlayer
FlashPlayer7,wasavailableforLinux.TherearebothActiveXcontroland
7
Netscape-styleversionsoftheplugin,butIrefertothemcollectivelyas"Flash
Player7."
TheFlashPlayer,specifically,thereleasespecifiedbymajorversionnumberx
FlashPlayer
andmajorbuildnumbery,asinFlashPlayer7.0.19.0.Theminorversion
x.0.y.0
numberandminorbuildnumberofpubliclyreleasedversionsisalways0.
Standalone AversionoftheFlashPlayerthatrunsdirectlyasanexecutableoffthelocal
Player
system,ratherthanasawebbrowserpluginorActiveXcontrol.

Projector

Aself-sufficientexecutablethatincludesbotha.swffileandaStandalone
Player.ProjectorscanbebuiltforeithertheMacintoshorWindowsoperating
systemusingFlash'sFile

Publishfeature.


ExampleFilesandResources
Theofficialcompanionwebsiteforthisbookis:
http://moock.org/eas2
Youcandownloadtheexamplefilesforthisbookat:
http://moock.org/eas2/examples
MoreexampleFlashcodecanbefoundattheCodeDepotfor
ActionScriptforFlashMX:TheDefinitiveGuide:
http://moock.org/asdg/codedepot
ForalonglistofFlash-relatedonlineresources,see:
http://moock.org/moockmarks
ForanextensivecollectionoflinkstohundredsofActionScript
2.0resources,see:
http://www.actionscripthero.com/adventures


TypographicalConventions
Inordertoindicatethevarioussyntacticcomponentsof
ActionScript,thisbookusesthefollowingconventions:

Menuoptions
Menuoptionsareshownusingthe character,suchasFile
Open.

Constantwidth
Indicatescodeexamples,codesnippets,clipinstance
names,framelabels,propertynames,variablenames,and
symbollinkageidentifiers.

Italic
Indicatesfunctionnames,methodnames,classnames,
packagenames,layernames,URLs,filenames,andfile
suffixessuchas.swf.Inadditiontobeingitalicizedinthe
bodytext,methodandfunctionnamesarealsofollowedby
parentheses,suchasduplicateMovieClip().

Constantwidthbold
Indicatestextthatyoumustenterverbatimwhenfollowing
astep-by-stepprocedure.Constantwidthboldisalso
usedwithincodeexamplesforemphasis,suchasto


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×

×