Flex Study Notes _ 07 basics of ActionScript 3.0 programming _ data types, operations, and procedures

Source: Internet
Author: User
Tags arithmetic operators

 

7.3 data types and operations

7.3.1 Data Types

When a variable or constant is declared, its data type must be specified:
Native data type: the language itself provides: String, integer, Boolean, etc.
Complex data types: composite types composed of basic data types: classes and interfaces.

Basic Data Type:
  • Boolean: Boolean, true, and false
  • INT: integer, which is a 32-bit binary integer in the range of-2147483648 ~ 2147483647. When the value exceeds the limit, it is automatically converted to number.
  • Null: null value, which is the default value of the string and all classes.
  • Number: integer or floating point type. data is stored in 64-bit dual-precision format. If no decimal point exists, the data is automatically converted to an integer. The minimum and maximum values are stored in the min_value and max_value attributes of the number object.
  • String: string, which is stored in Unicode encoding format.
  • Uint: Positive Integer type, 0 ~ 4294967295
  • Void: The value is undefined and can only be used as the return type of the function.


Complex data types: Object object, array, date, error object, function, Regexp regular expression, XML data object, and xmllist.
Objects are the base classes of all objects.

The default values for each type are as follows:

  • Object, array: NULL
  • Number: Nan
  • Int, uint: 0
  • Boolean: false
  • *: Undefined. The default value is undefined.


7.3.2 string

You can use single quotation marks and double quotation marks to declare a string, or use the string constructor to generate a string:
VaR str1: String = 'string ';
VaR str2: String = "string ";
VaR str3: String = new string ("string ");

Use the Escape Character "/" to escape the character after the symbol: "String/" test "= string" Test

String attributes:
  • Length: used to obtain the length of a string.
  • Contact (... ARGs): merges strings, or you can use + to merge strings.
  • Charat (INDEX): character used to obtain the index position.
  • Indexof (Val, starindex): Start from starindex to find the first position where Val appears in the string. -1 is returned If no result is found.
  • Split (delimiter, limit): returns the limit array separated by delimiter.
  • Substr (startindex, Len): captures the characters whose length is Len starting from the startindex position. If startindex is-1, it indicates the last position. When Len is greater than the maximum length, the maximum length value is automatically returned.
  • Substring (startindex, endindex): truncates the characters from startindex to endindex. Neither of the two parameters can be negative. Otherwise, it is converted to 0. If endindex is omitted, the default value is the length of the character.
  • Slice (startindex, endindex): Same as substring, and allowed startindex, endindex is a plural number.
  • Touppercase (): converts to uppercase
  • Tolowercase (): converts to lowercase


7.3.3 digital computing

Arithmetic Operators:
Symbol
Symbol description
Symbol
Symbol description
+
Addition operation
--
Minus 1
-
Subtraction + =
A = a + B
*
Multiplication -=
A = A-B
/
Division * =
A = a * B
%
Modulo operation /=
A = A/B
++
Add 1 Operation % =
A = A % B


When division is performed, if the divisor is 0, the return value is infinity.

Math class method description:

  • Math. Round (n): Rounding
  • Math. Floor (n): returns the maximum integer less than or equal to the specified number n.
  • Math. Ceil (n): returns the smallest integer greater than or equal to the specified number n.
  • Math. Pow (val1, val2): Calculate the val2power of val1.
  • Math. SQRT (VAL): square root of Val
  • Math. Max (val1, val2,... rest): the maximum value of A number given by Technology
  • Math. Min (val1, val2,... rest): the minimum value of A number given by Technology
  • Math. randow (): obtain a random number: less than 1 and greater than or equal to 0


7.3.4 use of Arrays

Create an array:
VaR arr: array = new array (); // The default element value is undefined.
VaR arr: array = new array (3); // create an array containing three elements.
VaR arr: array = new array ("1", "2", "3"); // define elements directly for the Array
VaR arr: array = [];
VaR arr: array = ["1", "2", "3"];
VaR arr: array = [3]; // instead of defining three elements, 3 is put as data into the array.

Get array elements:
Arr [0]: The first element. If the subscript is out of the range, undefined is returned.
Arr. Length: the length of a number.

Insert element:
  • Push (): add data to the end of the array, push ("flex ")
  • Unshift (): add data to the top of a number group, unshift ("flex ")
  • Splice (startindex, deletecount ,... values): insert data to the specified position of the array, startindex: subscript of the operation, deletecount: number of elements to be deleted ,... values: the data to be added.


Delete element:

  • Pop (): deletes the last element of the array.
  • Shift (): deletes the first element.
  • Splice (startindex, deletecount,... values): deletes any element from startindex, deletes the deletecount element from startindex, and adds the element values.


Sort:

  • Sort: sorts arrays of simple data structures.
  • Sorton: Sorting arrays of complex data structures
  • Reverse: reverse the existing order

Sorting rules: the sorting rules can be used simultaneously, for example, sort (array. caseinsensitive | array. Descending)

  • Array. caseinsensitive: case insensitive
  • Array. Descending: sort in descending order
  • Array. uniquesort: If all elements are unique and no duplicates exist, sort them. Otherwise, they are not sorted.
  • Array. returnindexedarray: returns the new order of sorted elements without modifying the original array.
  • Array. Numeric: sort by number size

Complex sorting:
Arr. sorton ("Age", array. Numeric); // "Age" is an attribute of an element, which is sorted by age.

Multi-dimensional array:
VaR arr: array = new array ();
Arr: Push (["1", "2"]);
Access: arr [0] [0]


7.3.5 type detection and conversion

Type Detection:
  • Typeof object: if the object is generated by the user's class, all objects are returned. Only basic types can be detected.


Data Type
Result
Data Type
Result
Array
Object
Object
Object
Boolean
Boolean
String
String
Function
Function
Uint
Number
Int
Number
XML
XML
Number
Number
Xmllist
XML


  • Object is type: accurately determines the object type. If the object is of type, true is returned; otherwise, false is returned.


Type conversion:

  • Implicit conversions: most of them are completed by Flash Player. For example, undefined is automatically converted to null.
  • Display conversion: You can write code to complete the conversion of the type (object). You can also convert the type of the object as. If the converted value is returned successfully, otherwise null is returned, no exception is thrown.

 

7.4 control procedures

7.4.1 SELECT statement

  • If process control:
If (conditional expression ){
// Code block
} Else {
// Code block
} Eles if (conditional expression ){
// Code block
}

  • Switch Process Control:
Switch (conditional expression ){
Case value 1:
// Code block
Break;
Case value 2:
// Code block
Break;
.....
Default:
// The preceding values do not match the statements in default execution.
}


7.4.2 cyclic statements

  • For Loop:
For (expression; conditional expression; expression ){
// Code block
}

  • For... in loop: name of the property of the traversal object
For (VAR property name in object ){
// Object [attribute name]
}

  • For each... in loop: traversing Object Property Values
For each (VAR attribute value in object ){
// Attribute values can be directly used here
}

  • While loop:
While (conditional expression ){
// Code block
}

  • Do... while loop:
Do {
// Code block
} While (conditional expression)


7.4.3 jump statement
  • Break: used to jump out of the current loop body and end the loop.
  • Continue: end this cycle and continue the next cycle.
  • Return: ends the operation of the function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.