2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩25頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、<p>  畢業(yè)設計(論文)外文資料</p><p><b>  原文及譯文</b></p><p>  專 業(yè) 計算機科學與技術</p><p>  班 級 08104121</p><p>  學 號 0810411504<

2、/p><p>  姓 名 高蕓蕓</p><p>  指 導 教 師 吳敏</p><p>  Flash 8 ActionScript Bible</p><p>  Joey Lott and Robert Reinhardt</p><p>  Understanding Da

3、tatypes</p><p>  When we talk about data, we’re talking about information or values. These values can be of many types. For example, even in a very simple movie you might still have a number, some text, and

4、a MovieClip instance. All three of these examples are data of different types —what ActionScript calls datatypes.</p><p>  Flash is actually capable of performing datatype conversions when necessary. However

5、, this can lead to some poor coding practices on the part of ActionScript developers. For this reason, the ActionScript 2.0 standards require that you pay closer attention to the datatypes you are using.</p><p

6、>  In ActionScript, you’ll work with many different datatypes. However, for the sake of understanding how these datatypes work, you can consider them in two basic categories: primitive types and reference types. The p

7、rimitive types are called primitive because they are the basic foundational datatypes, not because they lack importance. The reference datatypes are called reference types because they reference the primitive types.</

8、p><p>  Primitive datatypes include strings, numbers, Booleans, undefined, and null. We’ll examine each of these primitive datatypes a little more closely in this chapter. Reference datatypes are all objects, w

9、hich is the subject of much of the rest of this book, so we’ll defer the majority of the discussion of reference datatypes to those later chapters.</p><p>  Working with Strings</p><p>  Strings

10、 are characters or words. String values must always be enclosed in either single quotes or double quotes. Here are a few examples of strings:</p><p><b>  “a”</b></p><p><b>  ‘b

11、’</b></p><p><b>  “1”</b></p><p><b>  “Joey”</b></p><p><b>  ‘123’</b></p><p><b>  ‘a(chǎn)bc’</b></p><p>&

12、lt;b>  “****”</b></p><p>  Strings are used whenever you want to work with characters or words. For example, you can use strings to populate text fields in your movie, or you can use strings to prog

13、rammatically create names for new MovieClip instances. You’ve also already seen how strings can be used with actions such as trace(). The trace() action requires that you provide it with a message to display in the Outpu

14、t panel. That message must evaluate to a string value.</p><p>  trace(“I know him; Marley’s Ghost!”);</p><p>  As already mentioned, you can use either double quotes or single quotes when defini

15、ng a string value. Which you choose is often purely a matter of personal preference. There are two rules that you must follow, however, if you want your code to work without error. First, you must have a matching closing

16、 quote for every opening quote. And whichever type of quote you use to open the string literal must be used to close it. In other words, mismatched quotes are not allowed. Here are two examples of </p><p>  

17、“here is a string”</p><p>  ‘here is a string’</p><p>  And here are three examples of incorrect quotes on string literals:</p><p>  “here is a string’</p><p>  ‘here i

18、s a string”</p><p>  “here is a string</p><p>  There are times when more than personal preference might dictate which type of quotes you choose to use. Notice what would happen if you tried the

19、 following:</p><p>  trace(‘I know him; Marley’s Ghost!’);</p><p>  This line of code would actually cause an error because it would interpret the apostrophe as the closing quote and then fail t

20、o know what to do with the remainder of the string. This is easily remedied by using double quotes around the string:</p><p>  trace(“I know him; Marley’s Ghost!”);</p><p>  The inverse is true

21、as well, of course — if you want to use a double quotation mark as a character in a string literal, you can use single quotes around the entire value. The problem arises when you want to use both single and double quotat

22、ion marks as characters within a string literal. There is an easy way to accommodate this: by using special characters. To learn more about special characters, see Chapter 11.</p><p>  Working with Numbers&l

23、t;/p><p>  In Flash, all numbers are treated as the number datatype. Positive, negative, floating point, integer, and so forth, are all simply considered numbers, with no further differentiation generally requi

24、red on your part.</p><p>  To define a number, you need only type the number without any quotes. The following are examples of numbers.</p><p><b>  6</b></p><p><b>

25、;  12</b></p><p><b>  -1</b></p><p><b>  3.3</b></p><p><b>  1.8</b></p><p>  Number datatypes allow you to perform all kinds

26、of mathematical operations, as shown in the following examples:</p><p>  trace(5 + 5); // Displays: 10</p><p>  trace(5 – 4); // Displays: 1</p><p>  trace(5 / 2); // Displays: 2.5&

27、lt;/p><p>  It is important to understand when to use numbers and when to use strings. If you try to use a string when you really want to use a number, you can end up with unexpected results. For example:</p

28、><p>  trace(“5” + “5”); // Displays: 55</p><p>  In the example, the resulting value of addedAges is “55”, not 10 (as you may expect). This is because ActionScript treats the two values as strings

29、 and concatenates them, rather than adding the numeric values.</p><p>  However, it should also be understood that there are legitimate reasons for numbers to be treated as strings. For example, even though

30、a phone number is composed of numbers, it is usually treated as a string. And if you want to format the phone number with spaces, parentheses, dashes, and so on, it is necessary that the phone number be treated as a stri

31、ng by enclosing the value in quotation marks.</p><p>  Using Booleans</p><p>  Boolean data is data that can hold only two values: true and false. Boolean variables are used to test conditions w

32、ithin your Flash movie. Boolean values are used commonly in conditional expressions within statements such as the if statement and control structures such as the for and while statements. For more information about condi

33、tional statements and control structures, read the section “Using Statements That Control Flow: Control Structures” later in this chapter.</p><p>  Understanding the undefined and null Datatypes</p>&

34、lt;p>  ActionScript has two additional primitive datatypes — undefined and null — with which you’ll want to familiarize yourself. In order to have a better understanding of these datatypes, it is useful to first be fa

35、miliar with variables. Therefore, we’ll interweave the discussion of these two datatypes with the discussion of variables later in this chapter.</p><p>  Casting Data</p><p>  ActionScript allow

36、s you to tell Flash to convert a value to a specific datatype by what is known as casting. When you cast a value, you use the following syntax:</p><p>  Datatype(value)</p><p>  For example, you

37、 can cast a string to a number as follows:</p><p>  Number(“123”)</p><p>  When you are casting data you have to be careful. Some casting will have unexpected results. For example, the numeric v

38、alue of 0 can be converted to a Boolean false, and any nonzero value will be converted to true. For example:</p><p>  trace(Boolean(0)); // Displays: false</p><p>  trace(Boolean(1)); // Display

39、s: true</p><p>  Therefore, if you convert the string values of true and false, they will both convert to the Boolean true value because both string values are nonzero values.</p><p>  trace(Boo

40、lean(“true”)); // Displays: true</p><p>  trace(Boolean(“false”)); // Displays: true</p><p>  Using Variables</p><p>  In Flash movies you’re going to be using a lot of data. Now, w

41、ith all that data floating around, you’re going to want some way to keep track of it. This is where variables become very useful.</p><p>  A variable is a named container that you can use to hold or referenc

42、e some particular data. Once you have created a variable, you can store and retrieve data in the variable. Although a variable can contain only one value at a time, you can use the same variable to contain or reference d

43、ifferent data at different times. For example, if you create a variable named nYear, it may contain the value of 2005 at one point, but at another point it may contain the value 2006.</p><p>  Consider a ren

44、tal storage space as a metaphor for a variable. You can rent a space (declaring the variable), and when you do so, you can begin to place things in that space (assigning data to the variable). At a later time, you may wa

45、nt to view the things from the storage space (retrieving the value from the variable), or you may decide to place other contents in the storage space (assigning a new value to the same variable). And when you are done wi

46、th the storage space, you can stop renting it </p><p>  Declaring Variables</p><p>  Before you can meaningfully use a variable, you must first bring it into being by declaring it. Flash 8 and A

47、ctionScript 2.0 let you declare variables using strong typing. Strong typing means that when you create the variable, you also specify the type of data that it can hold. When you export your movie, Flash then makes sure

48、that you consistently tried to store the correct type of data in that variable. If Flash detects that you mismatched the datatype with the variable at any point, an error </p><p>  To declare a variable usin

49、g strong typing, use the following pattern:</p><p>  var variableName:Datatype;</p><p>  The var keyword lets Flash know that you are declaring a variable. The variable name is up to your choosi

50、ng, but it should follow the rules for variable naming (see the next section, “Naming Variables”). A colon separates the name of the variable and the name of the datatype, and there should be no space between the name, c

51、olon, or datatype. If you have code hinting turned on, you should get a drop-down list of built-in datatypes from which you can select. Alternatively, if you have defined your</p><p>  Here is an example in

52、which you declare a variable named nQuantity as a number:</p><p>  var nQuantity:Number;</p><p>  Now, you’ve declared a variable with the name nQuantity, and you’ve told Flash that all values y

53、ou assign to the variable must be numbers. The variable has been created, but you have not defined any value for it yet. If you use trace() to display the value of the variable, you can see that this is so:</p>&l

54、t;p>  trace(nQuantity);</p><p>  When you test this, you should see the value undefined appear in the Output panel. The value undefined is a special value that Flash uses for any variable that has not yet

55、 been assigned any value.</p><p>  Once a variable has been declared, you can assign a value to it using a simple assignment statement with an equals sign:</p><p>  var nQuantity:Number;</p&g

56、t;<p>  nQuantity = 6;</p><p>  You can also declare the variable and assign a value, or initialize the variable, all on one line:</p><p>  var nQuantity:Number = 6;</p><p> 

57、 In addition to the undefined value, there is another special value, null, that you can assign to a variable that indicates that the variable does not contain any other, specific value. While undefined is used to indicat

58、e no value has been assigned to a variable, you can use null to indicate that a variable has intentionally been left without any other value. It is often a good practice to initialize your variables to some value other t

59、han undefined. And because null allows you to quickly disting</p><p>  var nQuantity:Number = null;</p><p>  You can use a variable in any situation in which you could use the value the variable

60、 contains. You’ve already seen an example of this with the trace() actions. You can use a variable to tell Flash what message to output:</p><p>  var sMessage:String = “Welcome!”;</p><p>  trace

61、(sMessage);</p><p>  You can also perform other kinds of operations using variables, just as you would on the actual values themselves. For example:</p><p>  var nQuantity:Number = 6;</p>

62、<p>  var nPrice:Number = 9.99;</p><p>  trace(nQuantity * nPrice); // Displays: 59.94</p><p>  Naming Variables</p><p>  Now that you’ve looked at declaring and defining vari

63、ables, the next thing to examine is how to name the variables. There are two main parts to this discussion. First, there is the matter of using valid variable names that Flash will understand, so we’ll look at the rules

64、for naming variables. Second, we’ll examine some additional guidelines for naming variables that, while not strictly enforced by Flash, will aid you in creating more readable code.</p><p>  The following are

65、 the rules that you must follow for Flash to be able to understand your variable names:</p><p>  The first character must be an underscore (_), a dollar sign ($), or a letter. The first character cannot be a

66、 number. Although underscores and dollar signs are allowable as the first character, in practical application, you will almost always start the variable name with a letter.</p><p>  The subsequent characters

67、 must be underscores (_), dollar signs ($), letters, or numbers.</p><p>  Variable names can have no spaces.</p><p>  The name cannot be a keyword or other special value recognized by Flash. For

68、 example, the names MovieClip, true, String, and undefined are not allowable variable names because they already have other meanings in ActionScript.</p><p>  The name must be unique (within its scope). If y

69、ou create two variables with the same name in the same scope (more on scope in Chapters 4 and 5), the latter will overwrite the former.</p><p>  Next, let’s talk about some good naming conventions that you c

70、an use. First, because you’ll want to be using strong typing with all your variables, it is a good idea to have a convenient way to be reminded of what type of value a variable can hold. A system named Hungarian notation

71、 has been devised that can assist in this. For our purposes, we’ll use a modification of Hungarian notation specifically designed for ActionScript. With this system, you can prefix each variable name with a character (&l

72、t;/p><p>  This modified Hungarian notation convention is completely optional, but it can be very useful. It helps not only you, but also others who may read your code. By adding the appropriate prefix to the v

73、ariable name, it makes it immediately clear what type of datatype the variable can hold.</p><p>  It’s also important when naming your variables to make the names as descriptive as possible. For example, the

74、 variable name nQuantity is much more descriptive than nQ. Of course, the level of descriptiveness required depends on the context. For example, if your Flash application deals with quantities of widgets as well as cogs,

75、 nQuantity might not be sufficiently clear. It would be better, in such a case, to have variables named nQuantityCog and nQuantityWidget, for example. The more descriptive</p><p>  Remember that you cannot u

76、se spaces in your variable names. However, when you want to make your variable names descriptive, the names will often consist of more than one word. There are two conventions that are commonly used when naming variables

77、 with multiple words. The first of the two conventions is to use the underscore (_) to separate your words in the variable name. An example of this method follows:</p><p>  var sFirst_name:String = “Joey”;&l

78、t;/p><p>  The second of these conventions is what is known as the interCap method (also known as studlyCaps or camelCaps). The word “interCap” refers to the capitalization of the first letter of each word subs

79、equent to the first, using no spaces or underscores—internal capitalization. An example of this method is the following:</p><p>  var sFirstName:String = “Joey”;</p><p>  It would behoove you to

80、 use one of these conventions. Pick one that you like, and if you decide you prefer the other one later on, switch to it. In this book we tend to prefer the interCap method, so you see a preference for it in the examples

81、. But neither convention is more correct or offers any advantages over the other one.</p><p>  It is also important to remember that ActionScript is case-sensitive. This means that sFirstName, sFirstname, Sf

82、irstName, and so on are all different variables. If you accidentally type the name of a variable with incorrect capitalization, the result will be that Flash will not recognize that the variable is defined. Here is an ex

83、ample:</p><p>  var sFirstName:String = “Joey”;</p><p>  trace(sFirstName); // Displays: Joey</p><p>  trace(sfirstName); // Displays: undefined</p><p>  Using Expressi

84、ons</p><p>  Anyone who has taken even very basic arithmetic (using addition and subtraction and the like) has worked with expressions. Expressions are simply those parts of statements that evaluate to be eq

85、ual to something. Here are some very simple examples:</p><p><b>  1</b></p><p><b>  “abcd”</b></p><p><b>  nQuantity</b></p><p>  Ev

86、en though these examples are all either simple values or variables, they all evaluate to a single value, and therefore, are considered expressions. Slightly more complex (although still simple) expressions might look som

87、ething like this:</p><p><b>  1 + 1</b></p><p><b>  “a” + “b”</b></p><p>  nQuantity * nPrice</p><p>  Expressions are an important part of Acti

88、onScript. You use expressions in all kinds of situations.</p><p>  For example, you can use an expression within a trace() statement:</p><p>  trace(“Welcome!”);</p><p>  You can al

89、so use expressions in variable assignment statements:</p><p>  var nQuantity:Number = 6;</p><p>  var nPrice:Number = 9.99;</p><p>  var nTotal:Number = nQuantity * nPrice;</p>

90、;<p>  We’ll also look at other kinds of expressions that perform comparisons and tests. For example:</p><p><b>  6 < 10</b></p><p><b>  55 == 56</b></p>

91、<p>  In the preceding examples, we use comparison operators to determine how two values compare. The first expression is determining whether 6 is less than 10. That expression evaluates to true. The second express

92、ion determines whether 55 is equal to 56. That expression evaluates to false.</p><p>  There are many other examples of expressions, and we’ll examine some of them throughout the rest of this chapter.</p&

93、gt;<p>  Working with Operators</p><p>  As you have seen, expressions can be composed of a single value. But expressions can also be more complex by combining several different values to make one exp

94、ression. In expressions involving multiple values, there are two types of ActionScript elements involved: operands and operators. The operands are the values on which the operation acts. The operators determine the actio

95、n taken. In the expression 4 + 5, for instance, there are two values, or operands — 4 and 5 — and there is one operator: </p><p>  In the Actions toolbox you can see that the operators are grouped into six c

96、ategories: arithmetic, assignment, bitwise, comparison, logical, and miscellaneous. The following sections take a closer look at each of these groups, and the operators of which they are composed. We’ll look at each of t

97、hese groups in the order they are listed in the Actions toolbox, with the exception of the bitwise operators. We’ll look at the bitwise operators after the rest because, except in specialized situations, </p><

98、p>  Working with Arithmetic Operators</p><p>  The arithmetic operators should be familiar to you because they are, for the most part, the operators you used in math class. They are the operators used on

99、number operands for mathematical computations. The result of an operation using an arithmetic operator is a number value. Table 3-2 lists all the arithmetic operators.</p><p>  The addition, subtraction, mul

100、tiplication, and division operators don’t really require any discussion.They work just as you would expect them to.</p><p>  The modulo operator (%) may be new to you. Even if it is not new, you might need a

101、 little refresher on what it does. Quite simply, it returns the value of the remainder after the first operand is divided by the second. In the following example, we use the modulo operator with a variable nYear and the

102、second operand of 4. The result is 0. This means that 2004 is divisible by 4. In practical terms, the implication of this is that the year 2004 is a leap year.</p><p>  var nYear:Number = 2004;</p>&l

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論