February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Sorting array elements

Problem
Need sort array elements.

Solution
Using loop and indexOf.

Detailed explanation

var
foodArray:Array=[fruit_mc1,fruit_mc2,fruit_mc3,fruit_mc4,fruit_mc5,fruit_mc6,fruit_mc7,fruit_mc8,fruit_mc9,fruit_mc10,fruit_mc11,fruit_mc12,fruit_mc13,drink_mc1,drink_mc2,
drink_mc3, drink_mc4, drink_mc5, drink_mc6, drink_mc7, drink_mc8,
drink_mc9, drink_mc10, drink_mc11, drink_mc12, drink_mc13];

sortingAll_btn.label=”Wanna All”;
sortingAll_btn.useHandCursor=true;
sortingAll_btn.addEventListener(MouseEvent.CLICK, moveFoodToBags);
function moveFoodToBags(event:MouseEvent):void {
var instanceName:String;
fruitBasket_mc.alpha=.5;
drinkBasket_mc.alpha=.5;
for (var i:uint=0; i instanceName=foodArray[i].name;
if (instanceName.indexOf("fruit_mc")!=-1) {
foodArray[i].x=250;
foodArray[i].y=115;
} else {
foodArray[i].x=250;
foodArray[i].y=250;
}
}
}

index15
index23

Source:
sortingFood

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>