Tài liệu Flash: ActionScript Language Reference- P9 ppt

100 255 0
Tài liệu Flash: ActionScript Language Reference- P9 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

String.length 801 String.length Availability Flash Player 5. Usage my_str.length:Number Description Property; an integer specifying the number of characters in the specified String object. Because all string indexes are zero-based, the index of the last character for any string x is x.length - 1 . Example The following example creates a new String object and uses String.length to count the number of characters: var my_str:String = "Hello world!"; trace(my_str.length); // output: 12 The following example loops from 0 to my_str.length . The code checks the characters within a string, and if the string contains the @ character, true displays in the Output panel. If it does not contain the @ character, then false displays in the Output panel. function checkAtSymbol(my_str:String):Boolean { for (var i = 0; i<my_str.length; i++) { if (my_str.charAt(i) == "@") { return true; } } return false; } trace(checkAtSymbol("dog@house.net")); // output: true trace(checkAtSymbol("Chris")); // output: false An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • 802 Chapter 2: String.slice() Availability Flash Player 5. Usage my_str.slice(start:Number, [end:Number]) : String Parameters start A number; the zero-based index of the starting point for the slice. If start is a negative number, the starting point is determined from the end of the string, where -1 is the last character. end A number; an integer that is 1+ the index of the ending point for the slice. The character indexed by the end parameter is not included in the extracted string. If this parameter is omitted, String.length is used. If end is a negative number, the ending point is determined by counting back from the end of the string, where -1 is the last character. Returns A string; a substring of the specified string. Description Method; returns a string that includes the start character and all characters up to, but not including, the end character. The original String object is not modified. If the end parameter is not specified, the end of the substring is the end of the string. If the character indexed by start is the same as or to the right of the character indexed by end , the method returns an empty string. Example The following example creates a variable, my_str, assigns it a String value, and then calls the slice() method using a variety of values for both the start and end parameters. Each call to slice() is wrapped in a trace() statement that displays the output in the Output panel. // Index values for the string literal // positive index: 0 1 2 3 4 // string: L o r e m // negative index: -5-4-3-2-1 var my_str:String = "Lorem"; // slice the first character trace("slice(0,1): "+my_str.slice(0, 1)); // output: slice(0,1): L trace("slice(-5,1): "+my_str.slice(-5, 1)); // output: slice(-5,1): L // slice the middle three characters trace("slice(1,4): "+my_str.slice(1, 4)); // slice(1,4): ore trace("slice(1,-1): "+my_str.slice(1, -1)); // slice(1,-1): ore // slices that return empty strings because start is not to the left of end trace("slice(1,1): "+my_str.slice(1, 1)); // slice(1,1): trace("slice(3,2): "+my_str.slice(3, 2)); // slice(3,2): trace("slice(-2,2): "+my_str.slice(-2, 2)); // slice(-2,2): String.slice() 803 // slices that omit the end parameter use String.length, which equals 5 trace("slice(0): "+my_str.slice(0)); // slice(0): Lorem trace("slice(3): "+my_str.slice(3)); // slice(3): em An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See also String.substr(), String.substring() 804 Chapter 2: String.split() Availability Flash Player 5. Usage my_str.split("delimiter":String, [limit:Number]) : Number Parameters delimiter A string; the character or string at which my_str splits. limit A number; the number of items to place into the array. This parameter is optional. Returns An array; an array containing the substrings of my_str . Description Method; splits a String object into substrings by breaking it wherever the specified delimiter parameter occurs and returns the substrings in an array. If you use an empty string ( "" ) as a delimiter, each character in the string is placed as an element in the array. If the delimiter parameter is undefined, the entire string is placed into the first element of the returned array. Example The following example returns an array with five elements: var my_str:String = "P,A,T,S,Y"; var my_array:Array = my_str.split(","); for (var i = 0; i<my_array.length; i++) { trace(my_array[i]); } /* output: P A T S Y */ The following example returns an array with two elements, "P" and "A" : var my_str:String = "P,A,T,S,Y"; var my_array:Array = my_str.split(",", 2); trace(my_array); // output: P,A The following example shows that if you use an empty string ( "" ) for the delimiter parameter, each character in the string is placed as an element in the array: var my_str:String = new String("Joe"); var my_array:Array = my_str.split(""); for (var i = 0; i<my_array.length; i++) { trace(my_array[i]); } String.split() 805 /* output: J o e */ An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See Also Array.join() 806 Chapter 2: String.substr() Availability Flash Player 5. Usage my_str.substr(start:Number, [length:Number]) : String Parameters start A number; an integer that indicates the position of the first character in my_str to be used to create the substring. If start is a negative number, the starting position is determined from the end of the string, where the -1 is the last character. length A number; the number of characters in the substring being created. If length is not specified, the substring includes all the characters from the start to the end of the string. Returns A string; a substring of the specified string. Description Method; returns the characters in a string from the index specified in the start parameter through the number of characters specified in the length parameter. The substr method does not change the string specified by my_str ; it returns a new string. Example The following example creates a new string, my_str and uses substr() to return the second word in the string; first, using a positive start parameter, and then using a negative start parameter: var my_str:String = new String("Hello world"); var mySubstring:String = new String(); mySubstring = my_str.substr(6,5); trace(mySubstring); // output: world mySubstring = my_str.substr(-5,5); trace(mySubstring); // output: world An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • String.substring() 807 String.substring() Availability Flash Player 5. Usage my_str.substring(start:Number, [end:Number]) : String Parameters start A number; an integer that indicates the position of the first character of my_str used to create the substring. Valid values for start are 0 through String.length - 1. If start is a negative value, 0 is used. end A number; an integer that is 1+ the index of the last character in my_str to be extracted. Valid values for end are 1 through String.length . The character indexed by the end parameter is not included in the extracted string. If this parameter is omitted, String.length is used. If this parameter is a negative value, 0 is used. Returns String: a substring of the specified string. Description Method; returns a string comprising the characters between the points specified by the start and end parameters. If the end parameter is not specified, the end of the substring is the end of the string. If the value of start equals the value of end , the method returns an empty string. If the value of start is greater than the value of end , the parameters are automatically swapped before the function executes and the original value is unchanged. Example The following example shows how to use substring() : var my_str:String = "Hello world"; var mySubstring:String = my_str.substring(6,11); trace(mySubstring); // output: world The following example shows what happens if a negative start parameter is used: var my_str:String = "Hello world"; var mySubstring:String = my_str.substring(-5,5); trace(mySubstring); // output: Hello An example is also in the Strings.fla file in the Examples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • 808 Chapter 2: String.toLowerCase() Availability Flash Player 5. Usage my_str.toLowerCase() : String Parameters None. Returns A string. Description Method; returns a copy of the String object, with all uppercase characters converted to lowercase. The original value is unchanged. Example The following example creates a string with all uppercase characters and then creates a copy of that string using toLowerCase() to convert all uppercase characters to lowercase characters: var upperCase:String = "LOREM IPSUM DOLOR"; var lowerCase:String = upperCase.toLowerCase(); trace("upperCase: " + upperCase); // output: upperCase: LOREM IPSUM DOLOR trace("lowerCase: " + lowerCase); // output: lowerCase: lorem ipsum dolor An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See Also String.toUpperCase() String.toUpperCase() 809 String.toUpperCase() Availability Flash Player 5. Usage my_str.toUpperCase() : String Parameters None. Returns A string. Description Method; returns a copy of the String object, with all lowercase characters converted to uppercase. The original value is unchanged. Example The following example creates a string with all lowercase characters and then creates a copy of that string using toUpperCase() : var lowerCase:String = "lorem ipsum dolor"; var upperCase:String = lowerCase.toUpperCase(); trace("lowerCase: " + lowerCase); // output: lowerCase: lorem ipsum dolor trace("upperCase: " + upperCase); // output: upperCase: LOREM IPSUM DOLOR An example is also found in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See also String.toLowerCase() 810 Chapter 2: ActionScript Language Reference " " (string delimiter) Availability Flash Player 4. Usage "text" Parameters text A sequence of zero or more characters. Returns Nothing. Description String delimiter; when used before and after characters, quotation marks ("") indicate that the characters have a literal value and are considered a string, not a variable, numerical value, or other ActionScript element. Example The following example uses quotation marks ("") to indicate that the value of the variable yourGuess is the literal string "Prince Edward Island" and not the name of a variable. The value of province is a variable, not a literal; to determine the value of province , the value of yourGuess must be located. var yourGuess:String = "Prince Edward Island"; submit_btn.onRelease = function() { trace(yourGuess); }; // displays Prince Edward Island in the Output panel See also String class, String() CHAPTER 2 ActionScript Language Reference [...]... Interface (UI) Language In Flash Player 6 on the Microsoft Windows platform, System.capabilities .language returns the User Locale, which controls settings for formatting dates, times, currency and large numbers In Flash Player 7 on the Microsoft Windows platform, this property now returns the UI Language, which refers to the language used for all menus, dialog boxes, error messages and help files Language. .. no Other/unknown xu Polish pl Portuguese 830 Tag cs pt Chapter 2: ActionScript Language Reference Language Tag Russian ru Simplified Chinese zh-CN Spanish es Swedish sv Traditional Chinese zh-TW Turkish tr Example The following example traces the value of this read-only property: trace(System.capabilities .language) ; System.capabilities .language 831 System.capabilities.localFileReadDisable Availability... trace(System.capabilities.isDebugger); System.capabilities.isDebugger 829 System.capabilities .language Availability Flash Player 6 Behavior changed in Flash Player 7 Usage System.capabilities .language: String Description Read-only property; indicates the language of the system on which the player is running This property is specified as a lowercase two-letter language code from ISO 639-1 For Chinese, an additional uppercase two-letter... Chinese The languages themselves are named with the English tags For example, fr specifies French This property changed in two ways for Flash Player 7 First, the language code for English systems no longer includes the country code In Flash Player 6, all English systems return the language code and the two-letter country code subtag (en-US) In Flash Player 7, English systems return only the language code... getColor 256 levels of recursion were exceeded in one action list This is probably an infinite loop Further execution of actions has been disabled in this movie 812 Chapter 2: ActionScript Language Reference CHAPTER 2 ActionScript Language Reference switch Availability Flash Player 4 Usage switch (expression){ caseClause: [defaultClause:] } Parameters expression Any expression caseClause A case keyword... break; default : trace("you pressed some other key"); } }; Key.addListener(listenerObj); See also === (strict equality), break, case, default, if 814 Chapter 2: ActionScript Language Reference System.capabilities object CHAPTER 2 ActionScript Language Reference Availability Flash Player 6 Description You can use the System.capabilities object to determine the abilities of the system and player hosting... coming from a microphone; false otherwise The server string is AE Example The following example traces the value of this read-only property: trace(System.capabilities.hasAudioEncoder); 820 Chapter 2: ActionScript Language Reference System.capabilities.hasEmbeddedVideo Availability Flash Player 6 r65 Usage System.capabilities.hasEmbeddedVideo:Boolean Description Read-only property: a Boolean value that is... system that has an MP3 decoder; false otherwise The server string is MP3 Example The following example traces the value of this read-only property: trace(System.capabilities.hasMP3); 822 Chapter 2: ActionScript Language Reference System.capabilities.hasPrinting Availability Flash Player 6 r65 Usage System.capabilities.hasPrinting:Boolean Description Read-only property: a Boolean value that is true if the... Communication Server; false otherwise The server string is SB Example The following example traces the value of this read-only property: trace(System.capabilities.hasScreenBroadcast); 824 Chapter 2: ActionScript Language Reference System.capabilities.hasScreenPlayback Availability Flash Player 6 r79 Usage System.capabilities.hasScreenPlayback:Boolean Description Read-only property: a Boolean value that... play streaming audio; false otherwise The server string is SA Example The following example traces the value of this read-only property: trace(System.capabilities.hasStreamingAudio); 826 Chapter 2: ActionScript Language Reference System.capabilities.hasStreamingVideo Availability Flash Player 6 r65 Usage System.capabilities.hasStreamingVideo:Boolean Description Read-only property: a Boolean value that . trace("[Clothes] I am setColor"); } } CHAPTER 2 ActionScript Language Reference 812 Chapter 2: ActionScript Language Reference Then create a new class called. e"); break; case "I" : CHAPTER 2 ActionScript Language Reference 814 Chapter 2: ActionScript Language Reference case "i" : trace("you

Ngày đăng: 14/12/2013, 14:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan