A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 41

Thread: Flash XML Play/Pause Button?

  1. #1
    Senior Member
    Join Date
    Dec 2004
    Posts
    459

    Flash XML Play/Pause Button?

    Hi,
    I have a flash xml slide show. I need to create a play pause toggle button that will stop the xml slide show and start it again.
    Does anyone know how I can do this?

    Here is the actionscript:
    Code:
    function loadXML(loaded)
    {
        if (loaded)
        {
            xmlNode = this.firstChild;
            image = [];
            caption = [];
            total = xmlNode.childNodes.length;
            for (i = 0; i < total; i++)
            {
                image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
            } // end of for
            firstImage1();
        }
        else
        {
            content = "file not loaded!";
        } // end else if
    } // End of the function
    function nextImage()
    {
        if (p < total - 1)
        {
            ++p;
            if (loaded == filesize)
            {
                picture._alpha = 0;
                picture.loadMovie("photos/" + image[p], 1);
                caption_txt.text = caption[p];
            } // end if
        } // end if
    } // End of the function
    function nextImage1()
    {
        if (p < total - 1)
        {
            ++p;
            if (loaded == filesize)
            {
                picture._alpha = 0;
                picture.loadMovie("photos/" + image[p], 1);
                caption_txt.text = caption[p];
                slideshow();
            } // end if
        } // end if
    } // End of the function
    function prevImage()
    {
        if (p > 0)
        {
            --p;
            picture._alpha = 0;
            picture.loadMovie("photos/" + image[p], 1);
            caption_txt.text = caption[p];
        } // end if
    } // End of the function
    function firstImage()
    {
        if (loaded == filesize)
        {
            picture._alpha = 0;
            picture.loadMovie("photos/" + image[0], 1);
            caption_txt.text = caption[0];
        } // end if
    } // End of the function
    function firstImage1()
    {
        if (loaded == filesize)
        {
            picture._alpha = 0;
            picture.loadMovie("photos/" + image[0], 1);
            caption_txt.text = caption[0];
            slideshow();
        } // end if
    } // End of the function
    function slideshow()
    {
        function pause_slideshow()
        {
            clearInterval(myInterval);
            if (p == total - 1)
            {
                p = 0;
                firstImage1();
            }
            else
            {
                nextImage1();
            } // end else if
        } // End of the function
        myInterval = setInterval(pause_slideshow, 4000);
    } // End of the function
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("photos.xml");
    listen = new Object();
    listen.onKeyDown = function ()
    {
        if (Key.getCode() == 37)
        {
            prevImage();
        }
        else if (Key.getCode() == 39)
        {
            nextImage();
        } // end else if
    };
    Key.addListener(listen);
    previous_btn.onRelease = function ()
    {
        prevImage();
    };
    next_btn.onRelease = function ()
    {
        nextImage();
    };
    p = 0;
    this.onEnterFrame = function ()
    {
        filesize = picture.getBytesTotal();
        loaded = picture.getBytesLoaded();
        preloader._visible = true;
        if (loaded != filesize)
        {
            preloader.preload_bar._xscale = 100 * loaded / filesize;
        }
        else
        {
            preloader._visible = false;
            if (picture._alpha < 100)
            {
                picture._alpha = picture._alpha + 10;
            } // end if
        } // end else if
    };
    
    ////////////Try the Pause and Play Toggle button down here ////////////////////
    
    
    	
    /*var playState:Boolean=true;
    btn_mc.onRollOver=function(){
    	this.gotoAndStop(2);
    }
    btn_mc.onRollOut=function(){
    	this.gotoAndStop(1);
    }
    */
    
    
    /////////this is where it goes to stop and start//////////////
    
    
    
    btn_mc.onRelease=function(){
    	this.gotoAndStop(1);
    	if(playState){
    		playState=false;
    		this.btnTxt_mc.gotoAndStop(2);
    		this._parent.stop();
    	}else{
    		playState=true;
    		this.btnTxt_mc.gotoAndStop(1);
    		this._parent.play();
    	}
    }

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Code:
    //
    var myInterval = null;
    var playState:Boolean = true;
    var image = new Array();
    var caption = new Array();
    var total = 0;
    var p = 0;
    //
    function loadXML(loaded) {
    	if (loaded) {
    		var xmlNode = this.firstChild;
    		image = [];
    		caption = [];
    		total = xmlNode.childNodes.length;
    		for (i = 0; i < total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		p = total;
    		slideshow();
    	} else {
    		content = "file not loaded!";
    	}
    	delete xmlNode;
    }
    function doLoading() {
    	var filesize = picture.getBytesTotal();
    	var loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100 * loaded / filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha < 100) {
    			picture._alpha = picture._alpha + 10;
    		} else {
    			delete this.onEnterFrame;
    		}
    	}
    }
    function showPic() {
    	caption_txt.text = caption[p];
    	picture._alpha = 0;
    	picture.loadMovie("photos/" + image[p], 1);
    	this.onEnterFrame = doLoading;
    }
    function nextImage() {
    	p = (p < total - 1) ? p + 1 : p;
    	showPic(p);
    }
    function prevImage() {
    	p = (p > 0) ? p - 1 : p;
    	showPic(p);
    }
    function slideshow() {
    	clearInterval(myInterval);
    	p = (++p >= total) ? 0 : p;
    	showPic(p);
    	myInterval = setInterval(slideshow, 4000);
    }
    //
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("photos.xml");
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == 37) {
    		prevImage();
    	} else if (Key.getCode() == 39) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    	prevImage();
    };
    next_btn.onRelease = function() {
    	nextImage();
    };
    btn_mc.onRelease = function() {
    	clearInterval(myInterval);
    	playState = !playState;
    	if (playState) {
    		slideshow();
    	}
    };

  3. #3
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    Code:
    //
    var myInterval = null;
    var playState:Boolean = true;
    var image = new Array();
    var caption = new Array();
    var total = 0;
    var p = 0;
    //
    function loadXML(loaded) {
    	if (loaded) {
    		var xmlNode = this.firstChild;
    		image = [];
    		caption = [];
    		total = xmlNode.childNodes.length;
    		for (i = 0; i < total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		p = total;
    		slideshow();
    	} else {
    		content = "file not loaded!";
    	}
    	delete xmlNode;
    }
    function doLoading() {
    	var filesize = picture.getBytesTotal();
    	var loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100 * loaded / filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha < 100) {
    			picture._alpha = picture._alpha + 10;
    		} else {
    			delete this.onEnterFrame;
    		}
    	}
    }
    function showPic() {
    	caption_txt.text = caption[p];
    	picture._alpha = 0;
    	picture.loadMovie("photos/" + image[p], 1);
    	this.onEnterFrame = doLoading;
    }
    function nextImage() {
    	p = (p < total - 1) ? p + 1 : p;
    	showPic(p);
    }
    function prevImage() {
    	p = (p > 0) ? p - 1 : p;
    	showPic(p);
    }
    function slideshow() {
    	clearInterval(myInterval);
    	p = (++p >= total) ? 0 : p;
    	showPic(p);
    	myInterval = setInterval(slideshow, 4000);
    }
    //
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("photos.xml");
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == 37) {
    		prevImage();
    	} else if (Key.getCode() == 39) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    	prevImage();
    };
    next_btn.onRelease = function() {
    	nextImage();
    };
    btn_mc.onRelease = function() {
    	clearInterval(myInterval);
    	playState = !playState;
    	if (playState) {
    		slideshow();
    	}
    };
    Thanks. I tried your actionscript but it still skips.

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    What is it skipping?

  5. #5
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    What is it skipping?
    Sorry, I forgot the link:
    Side Show
    When you click the next button you will see it skips.

  6. #6
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Side Show
    When you click the next button you will see it skips.

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Try changing the nextImage and prevImage as shown below...
    Code:
    function nextImage() {
    	p = (p < total - 1) ? p + 1 : p;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }
    function prevImage() {
    	p = (p > 0) ? p - 1 : p;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }

  8. #8
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    Try changing the nextImage and prevImage as shown below...
    Code:
    function nextImage() {
    	p = (p < total - 1) ? p + 1 : p;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }
    function prevImage() {
    	p = (p > 0) ? p - 1 : p;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }
    It stopped the slide show.

  9. #9
    :
    Join Date
    Dec 2002
    Posts
    3,518
    See attached file (MX2004)...
    Last edited by dawsonk; 08-21-2008 at 10:07 AM.

  10. #10
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    See attached file (MX2004)...
    Thanks I will try to encorporate it.
    However, does it have a play pause button? I do need that.
    Thank you again.

  11. #11
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes, the green/red circle is the pause/play button.

  12. #12
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    Yes, the green/red circle is the pause/play button.
    This is wonderful, dawonk! So far it works perfectly. How in the world did you mangae that? How did you get such a good grasp on actionscript and xml?
    What steps can I take to get to where you are in the area? I am already there with the front end area. I have to strengthen the programming/coding area.

  13. #13
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Quote Originally Posted by dawsonk
    Yes, the green/red circle is the pause/play button.
    Thanks so much! It works great! I have another xml question for ya.
    Here is the link. Improved Slide Show
    I want some copy to show up under the xml captions. I tried using html tags but they don't work. How can I have the caption and text under it?
    Thanks again for your great help!

    Here is the xml:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
    <pic>
    <image>ice1.jpg</image>
    <caption>This is photo 1</caption>
    </pic>
    <pic>
    <image>ice2.jpg</image>
    <h1>This is photo 2</h1>
    </pic>
    <pic>
    <image>ice3.jpg</image>
    <caption>This is photo 3</caption>
    </pic>
    <pic>
    <image>ice4.jpg</image>
    <caption>This is photo 4</caption>
    </pic>
    <pic>
    <image>ice5.jpg</image>
    <caption>This is photo 5</caption>
    </pic>
    <pic>
    <image>ice6.jpg</image>
    <caption>This is photo 6 </caption>
    </pic>
    <pic>
    <image>ice7.jpg</image>
    <caption>This is photo 7</caption>
    </pic>
    <pic>
    <image>ice8.jpg</image>
    <caption>This is photo 8</caption>
    </pic>
    <pic>
    <image>ice9.jpg</image>
    <caption>This is photo 9</caption>
    </pic>
    <pic>
    <image>ice10.jpg</image>
    <caption>This is photo 10</caption>
    </pic>
    </images>

  14. #14
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Hi Dawsonk,
    Can you tell me how I can get the next and previous button to loop to the first and last of the slide show?
    Slide Show Here
    What you sent me works great. I just have to get the slideshow to loop with the buttons.
    Thanks a lot!

  15. #15
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function nextImage() {
    	p = (p < total - 1) ? p + 1 : 0;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }
    function prevImage() {
    	p = (p > 0) ? p - 1 : total - 1;
    	showPic(p);
    	if (playState) {
    		clearInterval(myInterval);
    		myInterval = setInterval(slideshow, 4000);
    	}
    }

  16. #16
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Thanks man. But now the buttons don't work.
    Here is the actionscript...

    ///////////////// New button to loop here ////////////
    function nextImage() {
    p = (p < total - 1) ? p + 1 : 0;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : total - 1;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    /////////////////////////////////////////////////////
    /*
    ////////////The buttons are here //////////////
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    prevImage();
    };
    next_btn.onRelease = function() {
    nextImage();
    };

    ///////////////////////////////////////////////
    */

  17. #17
    :
    Join Date
    Dec 2002
    Posts
    3,518
    ???
    This worked...
    Code:
    ///////////////// New button to loop here ////////////
    function nextImage() {
    p = (p < total - 1) ? p + 1 : p;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : p;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    And this disabled the buttons???
    Code:
    ///////////////// New button to loop here ////////////
    function nextImage() {
    p = (p < total - 1) ? p + 1 : 0;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : total - 1;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    I'm missing something...

  18. #18
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    Sorry I posted the same code. My mistake. Let me repost it. sorry


    Quote Originally Posted by dawsonk
    ???
    This worked...
    Code:
    ///////////////// New button to loop here ////////////
    function nextImage() {
    p = (p < total - 1) ? p + 1 : p;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : p;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    And this disabled the buttons???
    Code:
    ///////////////// New button to loop here ////////////
    function nextImage() {
    p = (p < total - 1) ? p + 1 : 0;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : total - 1;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    I'm missing something...

  19. #19
    Senior Member
    Join Date
    Dec 2004
    Posts
    459
    This is what you sent me today. It does the slide but does not allow the next button or previous button to work

    function nextImage() {
    p = (p < total - 1) ? p + 1 : 0;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    function prevImage() {
    p = (p > 0) ? p - 1 : total - 1;
    showPic(p);
    if (playState) {
    clearInterval(myInterval);
    myInterval = setInterval(slideshow, 4000);
    }
    }
    This is what you originally sent me. It works great except that it does not allow the button to start over again after the last photo was chosen.
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    prevImage();
    };
    next_btn.onRelease = function() {
    nextImage();
    };

  20. #20
    :
    Join Date
    Dec 2002
    Posts
    3,518
    What is the code for prevImage and nextImage functions that you are currently using?

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