计算机科学与技术外文翻译.docx

上传人:b****2 文档编号:2070595 上传时间:2022-10-26 格式:DOCX 页数:25 大小:67.56KB
下载 相关 举报
计算机科学与技术外文翻译.docx_第1页
第1页 / 共25页
计算机科学与技术外文翻译.docx_第2页
第2页 / 共25页
计算机科学与技术外文翻译.docx_第3页
第3页 / 共25页
计算机科学与技术外文翻译.docx_第4页
第4页 / 共25页
计算机科学与技术外文翻译.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

计算机科学与技术外文翻译.docx

《计算机科学与技术外文翻译.docx》由会员分享,可在线阅读,更多相关《计算机科学与技术外文翻译.docx(25页珍藏版)》请在冰豆网上搜索。

计算机科学与技术外文翻译.docx

计算机科学与技术外文翻译

毕业设计(论文)外文资料

原文及译文

 

专业计算机科学与技术

班级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

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 党团建设

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1