1 import SWFLoader;
2 var loaderArray:Array = new Array();
3 var ArrangeArray:Array = new Array();
4
5 for (var i = 0; i < 50; i++)
6 {
7 loaderArray[i] = new SWFLoader("flower.swf");
8 addChild(loaderArray[i]);
9 loaderArray[i].x = Math.random() * 480;
10 loaderArray[i].y = Math.random() * 360;
11 loaderArray[i].name = "loader" + i;
12 loaderArray[i].addEventListener(MouseEvent.MOUSE_DOWN, drag);
13 loaderArray[i].addEventListener(MouseEvent.MOUSE_UP, drop);
14 pushToArray(loaderArray[i]);
15 }
16
17 function drag(e:MouseEvent)
18 {
19 e.currentTarget.startDrag();
20 }
21
22 function drop(e:MouseEvent)
23 {
24 e.currentTarget.stopDrag();
25 for (var j:uint = 0; j < ArrangeArray.length; j++)
26 {
27
28 if (ArrangeArray[j].targetName == e.currentTarget.name)
29 {
30
31 ArrangeArray[j].x = e.currentTarget.x;
32 ArrangeArray[j].y = e.currentTarget.y;
33 }
34 }
35 sortDepth();
36 }
37
38
39 function pushToArray(source_target)
40 {
41 ArrangeArray.push({targetName: source_target.name, y: source_target.y, x: source_target.x});
42 }
43
44
45
46 function sortDepth()
47 {
48 ArrangeArray.sortOn(["y", "x"], Array.NUMERIC);
49 for (var i:uint = 0; i < ArrangeArray.length; i++)
50 {
51 addChild(getChildByName(ArrangeArray[i].targetName));
52 }
53 }
54
55 sortDepth();
2 var loaderArray:Array = new Array();
3 var ArrangeArray:Array = new Array();
4
5 for (var i = 0; i < 50; i++)
6 {
7 loaderArray[i] = new SWFLoader("flower.swf");
8 addChild(loaderArray[i]);
9 loaderArray[i].x = Math.random() * 480;
10 loaderArray[i].y = Math.random() * 360;
11 loaderArray[i].name = "loader" + i;
12 loaderArray[i].addEventListener(MouseEvent.MOUSE_DOWN, drag);
13 loaderArray[i].addEventListener(MouseEvent.MOUSE_UP, drop);
14 pushToArray(loaderArray[i]);
15 }
16
17 function drag(e:MouseEvent)
18 {
19 e.currentTarget.startDrag();
20 }
21
22 function drop(e:MouseEvent)
23 {
24 e.currentTarget.stopDrag();
25 for (var j:uint = 0; j < ArrangeArray.length; j++)
26 {
27
28 if (ArrangeArray[j].targetName == e.currentTarget.name)
29 {
30
31 ArrangeArray[j].x = e.currentTarget.x;
32 ArrangeArray[j].y = e.currentTarget.y;
33 }
34 }
35 sortDepth();
36 }
37
38
39 function pushToArray(source_target)
40 {
41 ArrangeArray.push({targetName: source_target.name, y: source_target.y, x: source_target.x});
42 }
43
44
45
46 function sortDepth()
47 {
48 ArrangeArray.sortOn(["y", "x"], Array.NUMERIC);
49 for (var i:uint = 0; i < ArrangeArray.length; i++)
50 {
51 addChild(getChildByName(ArrangeArray[i].targetName));
52 }
53 }
54
55 sortDepth();