Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 149 150 151 152 153 154 < 155 > 156 157 158 159 160 161 .. 419 >> Next

Sorting with Sort Flags
You can also use all the same sorting flags with sortOn() that you can use with sort(). If you are sorting on a single key then the first parameter for the sortOn() method is still the key name. Then, you can pass the method a sorting flag constant as the second parameter. Here is an example:
function displayArray(aArray:Array) { var sElement:String = null;
for(var i:Number = 0; i < aArray.length; i++) { sElement = ""; for(var key in aArray[i]) {
sElement += aArray[i][key] + " ";
}
trace(sElement);
}
}
var aCars:Array = new Array();
aCars.push({make
aCars.push({make
aCars.push({make
"Oldsmobile", model: "Alero", extColor: "blue"}); "Honda", model: "Accord", extColor: "red"}); "Volvo", model: "242", extColor: "red"}); aCars.sortOn("make", Array.DESCENDING); displayArray(aCars);
The result of this sort is as follows:
Volvo 242 red Oldsmobile Alero blue Honda Accord red
You can also use sorting flags when sorting with multiple keys. The first parameter should still be an array of the keys on which you want to sort. The second parameter should be the sorting flag constant. Here is an example:
Chapter 11 ¦ Using the Array Class 315
function displayArray(aArray:Array) { var sElement:String = null;
for(var i:Number = 0; i < aArray.length; i++) { sElement = ""; for(var key in aArray[i]) {
sElement += aArray[i][key] + " ";
}
trace(sElement);
}
}
var aCars:Array = new Array(); aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make: aCars.push({make:
"Oldsmobile", model: "Alero", extColor: "blue"});
"Honda", model: "Accord", extColor: "red"});
"Volvo", model: "242 DL", extColor: "red"});
"Oldsmobile", model: "Alero", extColor: "red"});
"Honda", model: "Accord", extColor: "gold"});
"Volvo", model: "242", extColor: "white"});
"Oldsmobile", model: "Aurora", extColor: "silver"});
"Honda", model: "Prelude", extColor: "silver"});
"Volvo", model: "242", extColor: "red"}); aCars.sortOn(["make","mode","extColor"], Array.DESCENDING); displayArray(aCars);
The Output panel for this example will display the following:
Volvo 242 white Volvo 242 red Volvo 242 DL red Oldsmobile Aurora silver Oldsmobile Alero red Oldsmobile Alero blue Honda Prelude silver Honda Accord red Honda Accord gold
And, of course, whether sorting on single or multiple keys, you can combine multiple sorting flags using the bitwise OR operator.
Reversing an Array
With the sorting flags that are now available there is little need for the reverse() method anymore. But should you want to quickly and simply reverse the order of an array’s elements, you can still use this method.
aEmployees.reverse();
Web
Resource
\
We'd like to know what you thought about this chapter. Visit www.flashsupport.com/ feedback to fill out an online form with your comments.
316 Part IV ¦ The Core Classes
Summary
¦ Arrays are indexed data structures in which each piece of data, called an element, has a unique index by which it can be referenced.
¦ Arrays can be created as array literals using the constructor methods, or as a returned value from a method such as slice() or concat().
¦ You can use the array access operator ([]) to read and write to the elements of an array. You place the index of the element you want to read or write to between the square brackets of the operator. Numbered indices start with 0.
¦ There are many ways to work with arrays. The basic array is the single-dimensional, numbered indices array. You can work with multiple arrays with corresponding elements in what are known as parallel arrays. And you can even create arrays of arrays to provide support for more complex collections of data.
¦ You can sort your arrays using many of ActionScript’s built-in sorting options.
¦¦¦
The Number Class
APT
Chances are good that in the majority of Flash applications, you’ll be using numbers. Numbers show up when you’re using ActionScript to animate objects, calculate prices, quantities, and so on, and in a whole lot of scenarios in which you might not even have thought of numbers. In this chapter, you’ll get a chance to learn more about different types of numbers and how to work with them.
Understanding Number Types
Although all numbers in ActionScript are classified as the number datatype, there are different types of numbers with which you can work. The following sections examine some of these types.
Integers and Floating-Point Numbers
The first category of numbers is base-10. These numbers should be familiar to you. They are the numbers that you use to count in everyday life. But within this category, you can have two classifications of precision: integers and floating-point numbers.
Integers are whole numbers, including 0 and negative values. The following are examples of integers:
1, 25, 0, -36, -3, 2932
Integers are the numbers you use to count whole things. For instance, you count frames in integer values — you cannot have anything between two frames. You use integers as indices for arrays, and you use integers to count most items (for example, people, paper clips, and pens).
Previous << 1 .. 149 150 151 152 153 154 < 155 > 156 157 158 159 160 161 .. 419 >> Next