通过 XML 自动滚动图像
我有下面的脚本,其中我通过 XML 调用一些图像,并创建一个画廊,该画廊每 3 秒向左移动一次,自动传递图片。但我的图像宽度尺寸不同,高度相同。
var dados:XML = new XML(); dados.ignoreWhite = true; dados.load("xml/" + _root.xmlport); dados.onLoad = function():Void { qtd = this.childNodes[0].childNodes.length; _root.qualqtd = this.childNodes[0].childNodes.length; for (j = 0; j @= qtd; j++) { mcPanels.item_mc.duplicateMovieClip("item_mc" + j,mcPanels.getNextHighestDepth()); mcPanels["item_mc" + j].imagem = this.childNodes[0].childNodes[j].childNodes[0].attributes.imagem; mcPanels["item_mc" + j].tamanho = this.childNodes[0].childNodes[j].childNodes[1].attributes.tamanhofoto; mcPanels["item_mc" + j].foto.loadMovie(mcPanels["item_mc" + j].imagem); mcPanels["item_mc" + j]._x = j * mcPanels["item_mc" + j].tamanho; mcPanels["item_mc" + j]._y = 0; } }; var i:Number = 0; var easing:Number = 0.2; var clipNum:Number = _root.qualqtd; var myInterval = setInterval(moveIt, 3000); var dir:Number = 1; function moveIt() { if (dir == 1) { targX = Math.floor(mcPanels._x - 450); i++; if (i == clipNum) { dir = -dir; } } else if (dir == -1) { targX = Math.floor(mcPanels._x + 450); i--; if (i == 0) { dir = -dir; } } onEnterFrame = function () { var dx:Number = Math.floor(targX - mcPanels._x); mcPanels._x += dx * easing; if (Math.abs(dx) @ .5) { mcPanels._x = targX; delete onEnterFrame; } }; }
我怎样才能让这个脚本获取每个图像的大小并根据其宽度移动? 我的 XML 看起来像:
menu
item
fotoevento imagem='portfolio/15anos/15anos_01.jpg'/
tamanhofoto tamanhofoto='100'/
/item
item
fotoevento imagem='portfolio/15anos/15anos_02.jpg'/
tamanhofoto tamanhofoto='50'/
/item
item
fotoevento imagem='portfolio/15anos/15anos_03.jpg'/
tamanhofoto tamanhofoto='100'/
/item
/menu
值为 450,这是我赋予他的值 移动,我知道应该改变,但不知道如何......
有人可以帮助我吗?
在脚本上 @ 它的位置 <
I have the following scrip below, where I call some images through an XML, and create a gallery that every 3 seconds it moves to left, passing the pictures automatically. But my images are of different sizes in width, the height is the same.
var dados:XML = new XML(); dados.ignoreWhite = true; dados.load("xml/" + _root.xmlport); dados.onLoad = function():Void { qtd = this.childNodes[0].childNodes.length; _root.qualqtd = this.childNodes[0].childNodes.length; for (j = 0; j @= qtd; j++) { mcPanels.item_mc.duplicateMovieClip("item_mc" + j,mcPanels.getNextHighestDepth()); mcPanels["item_mc" + j].imagem = this.childNodes[0].childNodes[j].childNodes[0].attributes.imagem; mcPanels["item_mc" + j].tamanho = this.childNodes[0].childNodes[j].childNodes[1].attributes.tamanhofoto; mcPanels["item_mc" + j].foto.loadMovie(mcPanels["item_mc" + j].imagem); mcPanels["item_mc" + j]._x = j * mcPanels["item_mc" + j].tamanho; mcPanels["item_mc" + j]._y = 0; } }; var i:Number = 0; var easing:Number = 0.2; var clipNum:Number = _root.qualqtd; var myInterval = setInterval(moveIt, 3000); var dir:Number = 1; function moveIt() { if (dir == 1) { targX = Math.floor(mcPanels._x - 450); i++; if (i == clipNum) { dir = -dir; } } else if (dir == -1) { targX = Math.floor(mcPanels._x + 450); i--; if (i == 0) { dir = -dir; } } onEnterFrame = function () { var dx:Number = Math.floor(targX - mcPanels._x); mcPanels._x += dx * easing; if (Math.abs(dx) @ .5) { mcPanels._x = targX; delete onEnterFrame; } }; }
How can I make this script get the size of each image and move according to its width?
My XML looks like:
menu
item
fotoevento imagem='portfolio/15anos/15anos_01.jpg'/
tamanhofoto tamanhofoto='100'/
/item
item
fotoevento imagem='portfolio/15anos/15anos_02.jpg'/
tamanhofoto tamanhofoto='50'/
/item
item
fotoevento imagem='portfolio/15anos/15anos_03.jpg'/
tamanhofoto tamanhofoto='100'/
/item
/menu
Has a value of 450 which is the value that I put to him
move, I know it is there that should change, but do not know how ....
Can someone help me?
on script where is @ its <
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个数组来存储对每个照片持有人的引用。在 onLoad 函数中,在创建剪辑时存储剪辑引用:
然后在 moveIt() 函数中,跟踪当前剪辑并使用其宽度设置 targX 值:
要布局具有不同宽度的图像,您需要在循环浏览时跟踪每个图像的宽度。我认为 tamanho 是宽度(对不起我可怜的葡萄牙语!)
hth
Create an array to store a reference to each photo holder. In the onLoad function store the clip reference as you create it:
Then in the moveIt() function, track the current clip and use its width to set the targX value:
To layout the images with different widths, you need to track how wide each image is as you loop through. I assume tamanho is the width (sorry for my poor portuguese!)
hth