计算机科学与技术外文翻译.docx
《计算机科学与技术外文翻译.docx》由会员分享,可在线阅读,更多相关《计算机科学与技术外文翻译.docx(25页珍藏版)》请在冰豆网上搜索。
计算机科学与技术外文翻译
毕业设计(论文)外文资料
原文及译文
专业计算机科学与技术
班级08104121
学号0810411504
姓名
指导教师
原文出处:
Flash8ActionScriptBible,JoeyLottandRobertReinhardt,PublishedbyWileyPublishing,Inc.
Flash8ActionScriptBible
JoeyLottandRobertReinhardt
UnderstandingDatatypes
Whenwetalkaboutdata,we’retalkingaboutinformationorvalues.Thesevaluescanbeofmanytypes.Forexample,eveninaverysimplemovieyoumightstillhaveanumber,sometext,andaMovieClipinstance.Allthreeoftheseexamplesaredataofdifferenttypes—whatActionScriptcallsdatatypes.
Flashisactuallycapableofperformingdatatypeconversionswhennecessary.However,thiscanleadtosomepoorcodingpracticesonthepartofActionScriptdevelopers.Forthisreason,theActionScript2.0standardsrequirethatyoupaycloserattentiontothedatatypesyouareusing.
InActionScript,you’llworkwithmanydifferentdatatypes.However,forthesakeofunderstandinghowthesedatatypeswork,youcanconsiderthemintwobasiccategories:
primitivetypesandreferencetypes.Theprimitivetypesarecalledprimitivebecausetheyarethebasicfoundationaldatatypes,notbecausetheylackimportance.Thereferencedatatypesarecalledreferencetypesbecausetheyreferencetheprimitivetypes.
Primitivedatatypesincludestrings,numbers,Booleans,undefined,andnull.We’llexamineeachoftheseprimitivedatatypesalittlemorecloselyinthischapter.Referencedatatypesareallobjects,whichisthesubjectofmuchoftherestofthisbook,sowe’lldeferthemajorityofthediscussionofreferencedatatypestothoselaterchapters.
WorkingwithStrings
Stringsarecharactersorwords.Stringvaluesmustalwaysbeenclosedineithersinglequotesordoublequotes.Hereareafewexamplesofstrings:
“a”
‘b’
“1”
“Joey”
‘123’
‘abc’
“****”
Stringsareusedwheneveryouwanttoworkwithcharactersorwords.Forexample,youcanusestringstopopulatetextfieldsinyourmovie,oryoucanusestringstoprogrammaticallycreatenamesfornewMovieClipinstances.You’vealsoalreadyseenhowstringscanbeusedwithactionssuchastrace().Thetrace()actionrequiresthatyouprovideitwithamessagetodisplayintheOutputpanel.Thatmessagemustevaluatetoastringvalue.
trace(“Iknowhim;Marley’sGhost!
”);
Asalreadymentioned,youcanuseeitherdoublequotesorsinglequoteswhendefiningastringvalue.Whichyouchooseisoftenpurelyamatterofpersonalpreference.Therearetworulesthatyoumustfollow,however,ifyouwantyourcodetoworkwithouterror.First,youmusthaveamatchingclosingquoteforeveryopeningquote.Andwhichevertypeofquoteyouusetoopenthestringliteralmustbeusedtocloseit.Inotherwords,mismatchedquotesarenotallowed.Herearetwoexamplesofcorrectlymatchedquotesonstringliterals:
“hereisastring”
‘hereisastring’
Andherearethreeexamplesofincorrectquotesonstringliterals:
“hereisastring’
‘hereisastring”
“hereisastring
Therearetimeswhenmorethanpersonalpreferencemightdictatewhichtypeofquotesyouchoosetouse.Noticewhatwouldhappenifyoutriedthefollowing:
trace(‘Iknowhim;Marley’sGhost!
’);
Thislineofcodewouldactuallycauseanerrorbecauseitwouldinterprettheapostropheastheclosingquoteandthenfailtoknowwhattodowiththeremainderofthestring.Thisiseasilyremediedbyusingdoublequotesaroundthestring:
trace(“Iknowhim;Marley’sGhost!
”);
Theinverseistrueaswell,ofcourse—ifyouwanttouseadoublequotationmarkasacharacterinastringliteral,youcanusesinglequotesaroundtheentirevalue.Theproblemariseswhenyouwanttousebothsingleanddoublequotationmarksascharacterswithinastringliteral.Thereisaneasywaytoaccommodatethis:
byusingspecialcharacters.Tolearnmoreaboutspecialcharacters,seeChapter11.
WorkingwithNumbers
InFlash,allnumbersaretreatedasthenumberdatatype.Positive,negative,floatingpoint,integer,andsoforth,areallsimplyconsiderednumbers,withnofurtherdifferentiationgenerallyrequiredonyourpart.
Todefineanumber,youneedonlytypethenumberwithoutanyquotes.Thefollowingareexamplesofnumbers.
6
12
-1
3.3
1.8
Numberdatatypesallowyoutoperformallkindsofmathematicaloperations,asshowninthefollowingexamples:
trace(5+5);//Displays:
10
trace(5–4);//Displays:
1
trace(5/2);//Displays:
2.5
Itisimportanttounderstandwhentousenumbersandwhentousestrings.Ifyoutrytouseastringwhenyoureallywanttouseanumber,youcanendupwithunexpectedresults.Forexample:
trace(“5”+“5”);//Displays:
55
Intheexample,theresultingvalueofaddedAgesis“55”,not10(asyoumayexpect).ThisisbecauseActionScripttreatsthetwovaluesasstringsandconcatenatesthem,ratherthanaddin