positioning using previous object y coordinate and height
trying to loop out some pictures using a for loop and cant get them to be posiotioned directly beneath the previous picture, I have set the height number in my xml where I get the pictures from.
heres my actionscript code for the loop:
private function loadImage():void{
for(var i:int = 0;i<_items.length;i++){
_image = new LoadExternaly(_items[i].getImage(), _items[i].getText(), _items[i].getTitle(),开发者_开发百科 _items[i].getHeight());
_images.push(_image);
var prevItem:int = i;
if(prevItem>0) {
prevItem--;
}
_images[i].y = 0+(_images[prevItem].y+ _images[prevItem].getHeight());
addChild(_image);
}
}
Edit: This is how the code should look like if you are trying to place pictures directly beneath the previously added picture using a class with parameters, in this case the "LoadExternaly" is that class.
the problem is that you're setting the position before the image is added.
I'm not sure what LoadExternaly()
does, but I'm certain that it is asynchrounous, so you don't have the height of the previous object adjusted when you're adding the next position of the next one.
You'll need to put in some listener, where you adjust the position of the other consecutive objects after each object is loaded.
精彩评论