Ir para conteúdo
Fórum Script Brasil
  • 0

Next/Previous Button - XML


Bressan

Pergunta

Boa tarde, tudo bom?

Eu tenho uma galeria de fotos que funciona da seguinte maneira: é composta por várias galerias que são carregadas de um XML. Cada galeria dessas contem várias imagens. Quando se entr ana galeria, ela possui varios Thumbs e ao clicar em cada um deles, abre a respectiva imagem. Seu eu quiser trocar d eimagem, tenho que fechar a imagem atual e abrir uma outra. O que eu gostaria e ter uma segunda opção de mudar a de imagem, que seria quando eu clicar sobre o Thubs abrir a imagem, mas ter a opção de avançar e retornar com ela ampliada. Eu até consegui fazer algo, mais ainda sim não está ficando bom. Segue abaixo um pedaço codigo do XML. E o AS. Pesso paciência, pois é um pouco grande:

-------------------------------------------------------------------------------

<?xml version="1.0"?>
<galleries>
    <gallery title="3rd. millenium" intro=".">
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
    </gallery>
    <gallery title="fiber & fruit"  intro=".">
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
    </gallery>
    <gallery title="fiber & flower"  intro=".">
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
        <image>.</image>
    </gallery>
</galleries>
-------------------------------------------------------------------------------
/* -------------------- setting the variables -------------------- */
var menuSpeed:Number = 6;
var btnNext:Button = next_btn;
var btnPrev:Button = prev_btn;
var fotoAtual = 0;
var menuDown:Button = menuDown_btn;
var menuUp:Button = menuUp_btn;
var p:Number = 0;
menuUp._alpha = 0;
menuUp.enabled = false;
var firstLook:Boolean = true;
var menuButtons:MovieClip = galleryMenu_mc.buttonsHolder_mc;
var galleryMask:MovieClip = galleryMenu_mc.galleryMask_mc;
galleryMask._height = 340;
var imagesHolder:MovieClip = imagesHolder_mc;
var descText:TextField = desc_txt;
var imagesInGallery:Array = new Array();
var galleryNames:Array = new Array();
var galleryIntros:Array = new Array();
var descriptions:Array = new Array();
var tracker:Number = new Number();
var whatIsLoading:String = new String();
var galleryBtnLeftMargin:Number = 10;
var galleryBtnUpperMargin:Number = 60;
var galleryBtnVSpace:Number = 23;
var thumbMarginX:Number = 96;
var thumbMarginY:Number = 68;
/* -------------------- Aligning and positioning imagesHolder_mc, the logo and the description text field -------------------- */
imagesHolder._x = 243;
imagesHolder._y = galleryBtnUpperMargin;
logo_mc._x = logo_mc._y=galleryBtnLeftMargin;
desc_txt._x = 243;
desc_txt._y = 330;
/* -------------------- The welcome text -------------------- */
descText.text = "Click on a gallery name on the left to load its thumbnails. Remember, you can click on a thumbnail only when all the thumbnails in a gallery have been loaded. When you click on a thumbnail to see the big image, clicking on the big image will close it and you will return to the gallery. Use the button(s) above the galleries to scroll through them.";
/* -------------------- Importing and defining the DropShadow filter -------------------- */
import flash.filters.DropShadowFilter;
var shadowEffect:DropShadowFilter = new DropShadowFilter(3, 45, 0x000000, 100, 3, 3, 1, 3);
var thumbsFilter:Array = [shadowEffect];
/* -------------------- MovieClipLoader & Listener -------------------- */
var loader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
loader.addListener(myListener);
myListener.onLoadInit = function(target:MovieClip) {
    if (whatIsLoading == "thumb") {
        currentThumbnail.percent_txt._visible = false;
        currentThumbnail.filters = thumbsFilter;
        thumbClickable();
        tracker++;
        trace(tracker);
        if (tracker<howManyImages) {
            loadThumbnail();
        } else {
            enableThumbs();
        }
    } else if (whatIsLoading == "big") {
        target._alpha = 0;
        displayBigImage.percent_txt._visible = false;
        displayBigImage.filters = thumbsFilter;
        trace(displayBigImage);
        bigClickable();
        fadeIn();
    }
};
myListener.onLoadProgress = function(target:MovieClip, loaded:Number, total:Number) {
    percent = Math.floor(loaded/total*100);
    if (whatIsLoading == "thumb") {
        currentThumbnail.percent_txt._visible = true;
        currentThumbnail.percent_txt.text = percent+"%";
    } else if (whatIsLoading == "big") {
        displayBigImage.percent_txt._visible = true;
        displayBigImage.percent_txt.text = percent+"%";
    }
};
/* -------------------- loading XML -------------------- */
var imageGallery:XML = new XML();
imageGallery.ignoreWhite = true;
imageGallery.onLoad = function(success) {
    if (success) {
        parseGalleries();
            }
};
imageGallery.load("gallery/gallery.xml");

/* -------------------- parsing XML -------------------- */
function parseGalleries():Void {
    if (imageGallery.firstChild.nodeName == "galleries") {
        var rootNode:XMLNode = imageGallery.firstChild;
        for (i=0; i<rootNode.childNodes.length; i++) {
            if (rootNode.childNodes[i].nodeName == "gallery") {
                currentGallery = rootNode.childNodes[i];
                imagesInGallery.push(currentGallery.childNodes.length);
                galleryNames.push(currentGallery.attributes.title);
                galleryIntros.push(currentGallery.attributes.intro);
                currentGalleryTitle = rootNode.childNodes[i].attributes.title;
                currentGalleryButton = galleryMenu_mc.buttonsHolder_mc.attachMovie("gallery section button", "galleryButton"+i, galleryMenu_mc.buttonsHolder_mc.getNextHighestDepth());
                currentGalleryButton._x = 0;
                currentGalleryButton._y = galleryBtnVSpace*i;
                currentGalleryButton.sectionTitle_txt.text = "0"+(i+1)+" "+currentGalleryTitle.toUpperCase();
                for (j=0; j<currentGallery.childNodes.length; j++) {
                    if (currentGallery.childNodes[j].nodeName == "image") {
                        currentDescription = currentGallery.childNodes[j].firstChild.toString();
                        descriptions.push(currentDescription);
                    }
                }
            }
        }
    }
    numberOfGalleries = i;
    enableButtons(numberOfGalleries);
}
function enableButtons(numberOfGalleries:Number):Void {
    for (i=0; i<numberOfGalleries; i++) {
        pressedButton = galleryMenu_mc.buttonsHolder_mc["galleryButton"+i];
        pressedButton.onRollOver = function():Void  {
            this.gotoAndStop(2);
        };
        pressedButton.onRollOut = function():Void  {
            this.gotoAndStop(1);
        };
        pressedButton.onPress = function():Void  {
            removeMovieClip(thumbsDisplayer);
            removeMovieClip(displayBigImage);
            tracker = 0;
            thumbsDisplayer = imagesHolder.createEmptyMovieClip("thumbsDisplayer_mc", imagesHolder.getNextHighestDepth());
            clickedGallery = Number(this._name.substr(13));
            trace(clickedGallery);
            trace(this._name);
            howManyImages = imagesInGallery[clickedGallery];
            whichGallery = galleryNames[clickedGallery];
            descText.text = galleryIntros[clickedGallery];
            currentRow = 0;
            currentColumn = 0;
            loadThumbnail();
        };
    }
    enableGalleryNavigation();
}
function loadThumbnail() {
    currentThumbnail = thumbsDisplayer.attachMovie("thumbnail holder", "thumbnail"+(tracker+1), thumbsDisplayer.getNextHighestDepth());
    target = currentThumbnail.thumbImage_mc;
    if ((tracker%5) == 0 && tracker != 0) {
        currentRow += 1;
    }
    if (currentColumn>3) {
        currentColumn = 0;
    } else if (tracker == 0) {
        currentColumn = 0;
    } else {
        currentColumn += 1;
    }
    currentThumbnail._x = currentColumn*thumbMarginX;
    currentThumbnail._y = currentRow*thumbMarginY;
    currentThumbnail.percent_txt._visible = true;
    thumbNumber = currentThumbnail._name.substr(9);
    trace(_name.substr(9));
    thumbPath = "gallery/"+whichGallery+"/thumbs/"+thumbNumber+".jpg";
    whatIsLoading = "thumb";
    loader.loadClip(thumbPath,target);
    bigClickable();
}
function fadeIn():Void {
    target.onEnterFrame = function():Void  {
        this._alpha += 10;
        if (this._alpha>=100) {
            delete this.onEnterFrame;
            this._alpha = 100;
        }
    };
}
function thumbClickable():Void {
    currentThumbnail.onPress = function() {
        nextImage();
        prevImage();
        bigNumber = this._name.substr(9);
        trace(bigNumber);
        trace(this._name);
        displayBigImage = imagesHolder.attachMovie("big image holder", "bigImage_mc", imagesHolder.getNextHighestDepth());
        trace(imageHolder);
        target = displayBigImage.imageHolder_mc;
        trace(target);
        bigImagePath = "gallery/"+whichGallery+"/"+bigNumber+".jpg";
        trace(bigImagePath);
        whatIsLoading = "big";
        disableThumbs();
        loader.loadClip(bigImagePath,target);
        if (clickedGallery>0) {
            var descPosition:Number = 0;
            for (i=0; i<clickedGallery; i++) {
                descPosition += imagesInGallery[i];
            }
            descPosition = descPosition+Number(bigNumber)-1;
            imageDesc = descriptions[descPosition];
        } else {
            imageDesc = descriptions[Number(bigNumber)-1];
        }
        descText.text = imageDesc;
    };
    currentThumbnail.enabled = false;
}
function nextImage() {
    bntNext = _root.attachMovie("next", "next_btn", _root.getNextHighestDepth());
        trace(bntNext);
        next_btn._x = 714;
        next_btn._y=176, 5;
        next_btn._visible = true;
        next_bnt.enabled = true;
    next_btn.onPress = function() {
            trace("oi");    
    if (p<(howManyImages-1)) {
        p++;
        if (p>howManyImages) {
                p = 1;
            
        };
        if (whatIsLoading == "big") {
        target._alpha = 0;
        displayBigImage.percent_txt._visible = false;
        displayBigImage.filters = thumbsFilter;
        trace(displayBigImage);
        bigClickable();
        fadeIn();
        imageHolder.loadMovie("gallery/"+whichGallery+"/"+bigImage+".jpg"+1);
        }
    }
    }
}
function prevImage() {
    bntPrev = _root.attachMovie("prev", "prev_btn", _root.getNextHighestDepth());
        trace(bntPrev);
        prev_btn._x = 248;
        prev_btn._y=176, 5;
        prev_btn._visible = true;
        prev_bnt.enabled = true;
    prev_btn.onPress = function() {
        trace("tchau")
    if (p>0) {
        p--;
        if (whatIsLoading == "big") {
        target._alpha = 0;
        displayBigImage.percent_txt._visible = false;
        displayBigImage.filters = thumbsFilter;
        trace(displayBigImage);
        bigClickable();
        fadeIn();
        imageHolder.loadMovie("gallery/"+whichGallery+"/"+bigImage+".jpg"-1);
        }
    }
    }
}
function firstImage() {
    if (whatIsLoading == "big") {
        target._alpha = 0;
        imageHolder.loadMovie("gallery/"+whichGallery+"/"+bigImage+".jpg"-1);
        displayBigImage.percent_txt._visible = false;
            }
}
function picture_num() {
    current_pos = p+1;
    pos_txt.text = current_pos+" / "+howManyImages;
    bigClickable()
}
function bigClickable():Void {
        next_bnt.onPress = function() {
        next_btn._visible = false;
        prev_btn._visible = false;
        removeMovieClip(this);
        enableThumbs();
        descText.text = galleryIntros[clickedGallery];
    };
}
function disableThumbs():Void {
    for (i=0; i<howManyImages; i++) {
        thumbsDisplayer["thumbnail"+(i+1)].enabled = false;
    }
}
function enableThumbs():Void {
    for (i=0; i<howManyImages; i++) {
        thumbsDisplayer["thumbnail"+(i+1)].enabled = true;
    }
}
function bigClickable():Void {
    displayBigImage.onPress = function() {
        next_btn._visible = false;
        prev_btn._visible = false;
        removeMovieClip(this);
        enableThumbs();
        descText.text = galleryIntros[clickedGallery];
    };
}
function fadeIn():Void {
    target.onEnterFrame = function():Void  {
        this._alpha += 10;
        if (this._alpha>=100) {
            delete this.onEnterFrame;
            this._alpha = 100;
        }
    };
}
function enableGalleryNavigation():Void {
    menuDown.onPress = function() {
        if (firstLook) {
            menuUp._alpha = 100;
            menuUp.enabled = true;
            firstLook = false;
        }
        var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);
        if (menuButtons._y<=0 && menuTop>=galleryMask._height) {
            var targetPos:Number = menuButtons._y-galleryMask._height;
            menuDown.enabled = false;
            menuUp.enabled = false;
            menuButtons.onEnterFrame = function():Void  {
                menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;
                if (menuButtons._y<=(targetPos+0.8)) {
                    menuButtons._y = Math.round(targetPos);
                    delete menuButtons.onEnterFrame;
                    menuDown.enabled = true;
                    menuUp.enabled = true;
                }
            };
        }
    };
    menuUp.onPress = function() {
        var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);
        if (menuButtons._y<0 && menuTop>0) {
            var targetPos:Number = menuButtons._y+galleryMask._height;
            menuDown.enabled = false;
            menuUp.enabled = false;
            menuButtons.onEnterFrame = function():Void  {
                menuButtons._y += (-menuButtons._y+targetPos)/menuSpeed;
                if (menuButtons._y>=(targetPos-0.8)) {
                    menuButtons._y = Math.round(targetPos);
                    delete menuButtons.onEnterFrame;
                    menuDown.enabled = true;
                    menuUp.enabled = true;
                }
            };
        }
    };
}

-------------------------------------------------------------------------------

Se for possível, gostaria da ajuda de vocês.

Grato desde já.

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...