A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Creating stop/play buttons that include sublayers

  1. #1
    Junior Member
    Join Date
    Nov 2006
    Posts
    10

    Creating stop/play buttons that include sublayers

    Hi

    I have made a flash presentation that runs for about 3 minutes. As of now it runs in loops, with no interacting possible. I would, however, like to add a pause/stop button, and another one that plays the presentation from the same frame it was stopped.

    The problem is that I have several scenes (not the worst problem), and also lots of layers which again have sublayers with animation on them. Some of the scenes and layers have up to ten independent animations.

    When I add a script for stopping the presentation, the scene stops, but the sublayered animations continue to play, which of course messes up the presentation.

    I am of the understanding that creating lots of sublayers with animation isn't the best solution, but the presentation is made, and doing it all over isn't worth the effort just to get a pause button.

    Is there any way I can create a stop button that stops every animation on all layers and sublayers, and then play them again when I hit a play button?


    Thanks for any help you can give me on this matter.
    klobb

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Don't know if this will work, but maybe give it a try...
    Code:
    function chkAllMovies(instance) {
    	instance._CF = instance._currentframe;
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    function stopAllMovies(instance) {
    	if (instance._CF != instance._currentframe) {
    		instance._PP = true;
    		instance.stop();
    	}
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    function continueAllMovies(instance) {
    	if (instance._PP == true) {
    		instance._PP = false;
    		instance.play();
    	}
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    btnStop.onPress = function() {
    	chkAllMovies(_root);
    };
    btnStop.onRelease = function() {
    	stopAllMovies(_root);
    };
    btnGo.onPress = function() {
    	continueAllMovies(_root);
    };

  3. #3
    Junior Member
    Join Date
    Nov 2006
    Posts
    10
    Thanks for your reply. I have tried for a while now, but I can't get the code validated. Which parts of the code you wrote applies on general, and which ones do I have to assign my own names to?
    Furthermore, I marked my stop button and assigned the code for the stop button you wrote there, and then the same for my play button. Is that what you meant? Or should this all be in the very same script somehow?

    klobb

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes, you would use the instance name for your buttons. Shouldn't have to change anything else.

    Modified the following to use the SPACE bar to toggle pause/play.
    To test it, put this code in the first frame of your main timeline.
    Code:
    function chkAllMovies(instance) {
    	instance._CF = instance._currentframe;
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    function stopAllMovies(instance) {
    	if (instance._CF != instance._currentframe) {
    		instance._PP = true;
    		instance.stop();
    	}
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    function continueAllMovies(instance) {
    	if (instance._PP == true) {
    		instance._PP = false;
    		instance.play();
    	}
    	for (var n in instance) {
    		if (typeof (instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    var isPaused = false;
    var myListener:Object = new Object();
    myListener.onKeyDown = function() {
    	if (Key.getCode() == Key.SPACE) {
    		if (!isPaused){
    			chkAllMovies(_root);
    		}
    	}
    };
    myListener.onKeyUp = function() {
    	if (Key.getCode() == Key.SPACE) {
    		if (!isPaused){
    			stopAllMovies(_root);
    		}else{
    			continueAllMovies(_root);
    		}
    		isPaused = !isPaused;
    	}
    };
    Key.addListener(myListener);
    Last edited by dawsonk; 01-24-2007 at 11:02 AM. Reason: spelling

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