通过 XML 自动滚动图像

发布于 2024-11-14 06:22:00 字数 2130 浏览 2 评论 0原文

我有下面的脚本,其中我通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-11-21 06:22:00

创建一个数组来存储对每个照片持有人的引用。在 onLoad 函数中,在创建剪辑时存储剪辑引用:

//create the imageList
var imageList:Array =[];

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;
        //store a reference to the new foto holder
        imageList.push(mcPanels["item_mc" + j]);
    }
};

然后在 moveIt() 函数中,跟踪当前剪辑并使用其宽度设置 targX 值:

function moveIt() 
{
    var imageWidth:Number  = imageList[i]._width;
    trace("i" +i + "< "+ imageWidth);
    if (dir == 1) 
    {
        targX = Math.floor(mcPanels._x - imageWidth);
        i++;

        if (i == clipNum) 
        {
            dir = -dir;
        }

    } else if (dir == -1) 
    {
        targX = Math.floor(mcPanels._x + imageWidth);
        i--;

        if (i == 0) 
        {
            dir = -dir;
        }
    }
...
}

要布局具有不同宽度的图像,您需要在循环浏览时跟踪每个图像的宽度。我认为 tamanho 是宽度(对不起我可怜的葡萄牙语!)

dados.onLoad = function():Void  {
    qtd = this.childNodes[0].childNodes.length;
    _root.qualqtd = this.childNodes[0].childNodes.length;
    //track the width of the images
    var totalWidth:Number = 0;

    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);
        //dynamically set the x position based on previous image width
        mcPanels["item_mc" + j]._x = totalWidth;
        mcPanels["item_mc" + j]._y = 0;
        //store a reference to the new foto holder
        imageList.push(mcPanels["item_mc" + j]);

        //i assume you have the width in your xml
        totalWidth += mcPanels["item_mc" + j].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:

//create the imageList
var imageList:Array =[];

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;
        //store a reference to the new foto holder
        imageList.push(mcPanels["item_mc" + j]);
    }
};

Then in the moveIt() function, track the current clip and use its width to set the targX value:

function moveIt() 
{
    var imageWidth:Number  = imageList[i]._width;
    trace("i" +i + "< "+ imageWidth);
    if (dir == 1) 
    {
        targX = Math.floor(mcPanels._x - imageWidth);
        i++;

        if (i == clipNum) 
        {
            dir = -dir;
        }

    } else if (dir == -1) 
    {
        targX = Math.floor(mcPanels._x + imageWidth);
        i--;

        if (i == 0) 
        {
            dir = -dir;
        }
    }
...
}

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!)

dados.onLoad = function():Void  {
    qtd = this.childNodes[0].childNodes.length;
    _root.qualqtd = this.childNodes[0].childNodes.length;
    //track the width of the images
    var totalWidth:Number = 0;

    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);
        //dynamically set the x position based on previous image width
        mcPanels["item_mc" + j]._x = totalWidth;
        mcPanels["item_mc" + j]._y = 0;
        //store a reference to the new foto holder
        imageList.push(mcPanels["item_mc" + j]);

        //i assume you have the width in your xml
        totalWidth += mcPanels["item_mc" + j].tamanho;
    }
};

hth

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文