使用先前对象的 y 坐标和高度进行定位
尝试使用 for 循环循环出一些图片,但无法将它们直接放置在上一张图片的下方,我已经在从中获取图片的 xml 中设置了高度数字。
这是我的循环动作脚本代码:
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);
}
}
编辑:如果您尝试使用带有参数的类将图片直接放置在先前添加的图片下方,则代码应该是这样的,在本例中“LoadExternaly”就是该类。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您在添加图像之前设置位置。
我不确定
LoadExternally()
的作用,但我确定它是异步的,因此当您添加下一个位置时,不会调整前一个对象的高度下一张。您需要放入一些侦听器,在每个对象加载后调整其他连续对象的位置。
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.