Reputation: 23
I have a couple of display objects moving around the screen, the all belong to the same Vector
.
I would like to create a function that lets me pick an object with the lowest x
value at the moment the function is called.
Upvotes: 1
Views: 76
Reputation: 1954
This is quite easy and if you're into programming, you should be able to do it yourself, but if you're a beginner, I'll give you some code:
var vec:Vector.<DisplayObject> = new Vector.<DisplayObject>();
function getLowestXObject():DisplayObject
{
var minX:DisplayObject = vec[0];
for(var i:int = 1; i < vec.length; i++)
{
if(minX.x > vec[i].x)
{
minX = vec[i];
}
}
return minX;
}
Upvotes: 1