I've got a movie with three movie clip buttons that each play on mouse over with the following script: onClipEvent (enterFrame) { if (this.hitTest(_root._xmouse, _root._ymouse, true) ) { this.nextFrame(); } else { this.prevFrame(); } } I would like to have the buttons "self-run" or cycle through if the user is not interacting with them and pause if the user does mouse over one of the buttons. My clunky solution has been to create another movieclip that duplicates the animation of the buttons on it's timeline. There has to be a more elegant (i.e. scripted) solution to accomplish this. Maybe using a timer? Any help is greatly appreciated!
// move your functionality to a function on your main timeline. function btnAnimation { if (this.hitTest(_root._xmouse, _root._ymouse, true) ) { this.nextFrame(); } else { this.prevFrame(); } } // Create a function that controls the non-user dependent btn animation function fireBtnAnimation { setInterval(btnAnimation:Function, 10000:Number) : Number } // Fire the function onRollover _root.btn_1.onRollover = function () { mouseAnimation () ; } // On btn onRollout fire the function that controls the non-user dependent btn animation _root.btn1.onRollout = function () { fireBtnAnimation(); } Or something like that.
First, remove the old code. Give each of your "buttons" instance names, ie, btn1, btn2, btn3, btn4, etc. Then, place the following code on the FRAME that holds the buttons and add your button instances to th buttons array (line 1): buttons = [btn1, btn2, btn3, btn4]; iteration = 2000;//wait 2 seconds before choosing random for (var b = 0; b<buttons.length; b++) { var c_btn = buttons[b]; c_btn.onEnterFrame = function() { if (this.hitTest(_xmouse, _ymouse)) { selected_btn = null; if (id) { choosing = false; clearInterval(id); delete id; } this.nextFrame(); } else if (selected_btn != this) { this.prevFrame(); } }; } onEnterFrame = function () { var s = selected_btn; if (s) { if (s.dir == 1) { s.nextFrame(); } else { s.prevFrame(); } if (s._currentframe == s._totalframes) { s.dir = -1; } else if (s._currentframe == 1) { selected_btn = null; chooseRandom(); } } else if (!choosing) { choosing = true; chooseRandom(); } }; function chooseRandom() { if (id) { clearInterval(id); delete id; } var randF = function () { choosing = false; selected_btn = buttons[random(buttons.length)]; selected_btn.dir = 1; clearInterval(id); }; id = setInterval(randF, iteration); }
Don't see what you're looking for? Try a search.
|