A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Add back and previous buttons in slideshow

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    11

    Add back and previous buttons in slideshow

    Hi there.
    I started a tutorial about creating a flash slideshow. This is the as2 code:


    import mx.transitions.Tween;
    import mx.transitions.easing.*;

    var myShowXML = new XML();
    myShowXML.ignoreWhite = true;
    myShowXML.load("slideshow.xml");


    myShowXML.onLoad = function() {

    _root.myWidth = myShowXML.firstChild.attributes.width;
    _root.myHeight = myShowXML.firstChild.attributes.height;
    _root.mySpeed = myShowXML.firstChild.attributes.speed;

    _root.myImages = myShowXML.firstChild.childNodes;
    _root.myImagesNo = myImages.length;
    total = myShowXML.childNodes.length;

    createContainer();
    callImages();

    };


    function createContainer() {
    _root.createEmptyMovieClip("myContainer_mc",_root. getNextHighestDepth());


    myContainer_mc.lineTo(_root.myWidth,_root.myHeight );


    myContainer_mc._x = (Stage.width-myContainer_mc._width)/2;
    myContainer_mc._y = (Stage.height-myContainer_mc._height)/2;

    }



    function callImages() {

    _root.myMCL = new MovieClipLoader();
    _root.myPreloader = new Object();
    _root.myMCL.addListener(_root.myPreloader);

    _root.myClips_array = [];

    _root.myPreloader.onLoadStart = function(target) {

    _root.createTextField("myText_txt",_root.getNextHi ghestDepth(),0,0,100,20);
    _root.myText_txt._x = (Stage.width-_root.myText_txt._width)/2;
    _root.myText_txt._y = (Stage.height-_root.myText_txt._height)/1.08;
    _root.myText_txt.autoSize = "center";

    };

    _root.myPreloader.onLoadProgress = function(target){

    _root.myText_txt.text = "Loading.. "+_root.myClips_array.length+"/"+_root.myImagesNo+" Completed";

    }

    _root.myPreloader.onLoadComplete = function(target) {

    _root.myClips_array.push(target);
    target._alpha=0;

    if (_root.myClips_array.length == _root.myImagesNo) {

    myText_txt._alpha=0;

    moveSlide();
    myShowInt = setInterval(moveSlide, (_root.mySpeed*1000)+1000);

    }

    }

    for (i=0; i<_root.myImagesNo; i++) {

    temp_url = _root.myImages[i].attributes.url;
    temp_mc = myContainer_mc.createEmptyMovieClip(i, myContainer_mc.getNextHighestDepth());

    _root.myMCL.loadClip(temp_url,temp_mc);
    }

    }


    function moveSlide() {

    current_mc = _root.myClips_array[_root.target_mc];
    new Tween(current_mc, "_alpha", Strong.easeOut, 100, 0, 1, true);

    _root.target_mc++;

    if (_root.target_mc>=_root.myImagesNo) {
    _root.target_mc = 0;
    }

    next_mc = _root.myClips_array[_root.target_mc];
    new Tween(next_mc, "_alpha", Strong.easeOut, 0, 100, 1, true);

    }


    //I have created 2 buttons - NEXT with instance name:next_btn and PREV //with instance namerev_btn and these are the on(release) functions:
    previous_btn.onRelease = function() {

    prevImage();

    };
    next_btn.onRelease = function() {

    nextImage();

    }'



    The images load from xml file and change through moveSlide function.
    And now i need to create those 2 new functions in order to give the user the opportunity to change the images by him/herself.

    I found somewhere a piece of code about this kind of functions:

    p = 0;
    function nextImage() {

    if (p<(total-1)) {

    p++;
    if (loaded == filesize) {

    picture._alpha = 0;
    picture.loadMovie(image[p], 1);
    picture_num();
    }
    }

    }

    function prevImage() {

    if (p>0) {

    p--;
    picture._alpha = 0;
    picture.loadMovie(image[p], 1);
    picture_num();

    }

    }

    function picture_num() {

    current_pos = p+1;
    pos_txt.text = current_pos+" / "+total;

    }


    The link i got these functions is this:
    http://kirupa.com/developer/mx2004/x...otogallery.htm

    How can i adjust these functions to my slideshow?

    P.S. Sorry, but i am not an as2 expert but any help is welcomed.

    Thanks in advance

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    TL.DR;

    sorry, but you can just dump the whole code here. Maybe providing the FLA file and abit info on what to fix, would be lovely
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    11
    I am really sorry. Here is the .fla and the .xml file. I do not include the image folder for size saving.
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    What I saw from your post code: You replace those function with this.
    Actionscript Code:
    previous_btn.onRelease = prevImage;

    next_btn.onRelease = nextImage;




    arkitx

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Fixed it - it was really if you looked at the other codes, just follow these steps:

    1. Locate this line: myShowInt = setInterval(moveSlide, (_root.mySpeed*1000)+1000); (Line 76), and remove it if you don't want the fading to autoplay

    2. Change your nextImage function to this:

    Actionscript Code:
    function nextImage() {

    current_mc = _root.myClips_array[_root.target_mc];
    new Tween(current_mc, "_alpha", Strong.easeOut, 100, 0, 1, true);

    _root.target_mc++;

    if (_root.target_mc>=_root.myImagesNo) {
    _root.target_mc = 0;
    }

    //_root.myText_txt.text = _root.myImages[target_mc].attributes.title;
    next_mc = _root.myClips_array[_root.target_mc];
    new Tween(next_mc, "_alpha", Strong.easeOut, 0, 100, 1, true);

    }

    3. Change your prevImage function to this:

    Actionscript Code:
    function prevImage() {

    current_mc = _root.myClips_array[_root.target_mc];
    new Tween(current_mc, "_alpha", Strong.easeOut, 100, 0, 1, true);

    _root.target_mc--;

    if (_root.target_mc<1) {
    _root.target_mc = _root.myClips_array.length-1;
    }

    //_root.myText_txt.text = _root.myImages[target_mc].attributes.title;
    next_mc = _root.myClips_array[_root.target_mc];
    new Tween(next_mc, "_alpha", Strong.easeOut, 0, 100, 1, true);

    }

    -------

    The solution was really simple - just to understand the code from the tutorial, and then copy and paste portions of it and adjust it a little bit and make it your own

    Hope it helps!
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center