Alex
Alex

Reputation: 29

AS3 Array sorton() issue

I'm trying to sort an array of "tile" objects in as3 by the value of its "realY" property. This is my code:

    tiles.sortOn("realY", Array.DESCENDING);
    tiles.reverse();

    for each(var t:Tile in tiles)
    {
            trace(t.nearness);
    }

This is the output:

    6
6
6
6
6
7
7
7
7
7
7
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
10
10
10
10
10
10
10
10
10
11
11
11
11
11
11
11
11
11
11
12
12
12
12
12
12
12
12
12
12
12
13
13
13
13
13
13
13
13
13
13
13
13
14
14
14
14
14
14
14
14
14
14
14
14
14
15
15
15
15
15
15
15
15
15
15
15
15
15
15
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
17
17
17
17
17
17
17
17
17
17
17
17
17
17
17
17
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
26
26
26
26
26
26
26
26
26
26
26
26
26
26
26
27
27
27
27
27
27
27
27
27
27
27
27
27
27
28
28
28
28
28
28
28
28
28
28
28
28
28
29
29
29
29
29
29
29
29
29
29
29
29
30
30
30
30
30
30
30
30
30
30
30
2
31
31
31
31
31
31
31
31
31
31
32
32
32
32
32
32
32
32
32
33
33
33
33
33
33
33
33
34
34
34
34
34
34
34
35
35
35
35
35
35
36
36
36
36
36
37
37
37
37
38
38
38
39
39
40
3
3
4
4
4
5
5
5
5

As you can see, there are some random small numbers at the end. Why is this happening? Thanks

Upvotes: 1

Views: 3389

Answers (1)

Rick van Mook
Rick van Mook

Reputation: 2065

Try using your sortOn like this:

tiles.sortOn("realY", Array.NUMERIC | Array.DESCENDING);

By default Flash is sorting in alphabetical order. Check the documentation for more info.

Besides that, you're tracing the nearness property, not the realY property you sorted. So maybe that's a problem too.

Upvotes: 6

Related Questions