Ask a Question related to Macromedia Flash Actionscript, Design and Development.
-
MyFlashMXIN #1
getUTCMilliseconds() -vs.- setInterval
Hi I'm currently using setInterval in a script to show my SubMenu system for 5
sec, and then remove it...
This setInterval seems to work on some systems but not all annd has a horrable
bug in it.
Below is the current code (located in the main time line):
Is it possable to use the getUTCMilliseconds()? Say on rollOver save
UTCMill... to a variable and then on rollOut getUTC a second time and compare
the times. How could I Mod my current code to use this?
Examples & Tutorials welcomed! :-) Still learning AS....
Thanks in advance...
_global.elapsedTime=0;
aboutButton.onRollOver = function() {
duplicateMovieClip(SubAbout,"subAbout2",10);
setProperty(subAbout2,_x,0);
setProperty(subAbout2,_y,33);
};
aboutButton.onRollOut = function(){
killDelay1 = setInterval(rollOutDelay1,1000);
function rollOutDelay1(){
elapsedTime++;
if(elapsedTime>=5){
removeMovieClip(subAbout2);
elapsedTime=0;
clearInterval(killDelay1);
}
}
}
MyFlashMXIN Guest
-
still having problems with setInterval()
the code is like this: on (rollOver) { var qwer; qwer=setInterval(this._parent.sometextbox.scroll+=1,1000); } and it executes ONLY ONCE.... -
setInterval in 2.0.4
Hi I've just read the release notes for 2.0.4 and it says this: In the Flash Media Server 2 Server-Side ActionScript Language Reference... -
setInterval: been there, done that
The problem is i want to scroll a text using two objects: buttonUp and butonDown. I have done as i have been told: on the buttonUp (which is a... -
problems with setInterval()
i try doing something like this: on (press) { var intervalID; intervalID=setInterval(asdf(), 100); } function asdf() { //something; } -
setInterval
can setInterval timer be a varibles??? for example: t=500; setInterval(myfunction, t); t=t+100; i have tried this, but doesnt work.....can... -
kglad #2
Re: getUTCMilliseconds() -vs.- setInterval
assuming elapsedTime is initialized somewhere (otherwise that code is very
broken) you need a clearInterval() in your rollover event to avoid the problem
of more than one interval initiating and no way to stop them.
and yes, you can make your own setInterval() function with getTimer():
stopTime=getTimer()+5000;
clearInterval(delayI);
delayI=setInterval(delayF,50);
function delayF(){
if(getTimer()>=stopTime){
subAbout2.removeMovieClip();
clearInterval(delayI);
}
}
but what's the point? if you use clearInterval() correctly, you should just
use:
aboutButton.onRollOut=function(){
clearInterval(delayI);
delayI=setInterval(delayF,5000);
}
function delayF(){
subAbout2.removeMovieClip();
clearInterval(delayI);
}
kglad Guest
-
MyFlashMXIN #3
Re: getUTCMilliseconds() -vs.- setInterval
Missed that, where do I need, or better how should I initialist elapsedTime? I
thought I did that by declaring it a global w/ value of 0
Okay what I got now:
_global.elapsedTime = 0;
aboutButton.onRollOver = function() {
duplicateMovieClip(SubAbout, "subAbout2", 10);
setProperty(subAbout2, _x, 0);
setProperty(subAbout2, _y, 33);
};
aboutButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subAbout2.removeMovieClip();
clearInterval(delayI);
}
//=======================
contactButton.onRollOver = function() {
duplicateMovieClip(SubContact, "subContact2", 10);
setProperty(subContact2, _x, 0);
setProperty(subContact2, _y, 33);
};
contactButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subContact2.removeMovieClip();
clearInterval(delayI);
}
//========================================
servicesButton.onRollOver = function() {
duplicateMovieClip(SubServices, "subServices2", 10);
setProperty(subServices2, _x, 0);
setProperty(subServices2, _y, 33);
};
servicesButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subServices2.removeMovieClip();
clearInterval(delayI);
}
//============================================
storeButton.onRollOver = function() {
duplicateMovieClip(SubStore, "subStore2", 10);
setProperty(subStore2, _x, 0);
setProperty(subStore2, _y, 33);
};
storeButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subStore2.removeMovieClip();
clearInterval(delayI);
}
//========================================
webtrackButton.onRollOver = function() {
duplicateMovieClip(SubWebtrack, "subWebtrack2", 10);
setProperty(subWebtrack2, _x, 0);
setProperty(subWebtrack2, _y, 33);
};
webtrackButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subWebtrack2.removeMovieClip();
clearInterval(delayI);
}
stop();
MyFlashMXIN Guest
-
MyFlashMXIN #4
Re: getUTCMilliseconds() -vs.- setInterval
Missed that, where do I need, or better how should I initialist elapsedTime? I
thought I did that by declaring it a global w/ value of 0
Okay what I got now:
_global.elapsedTime = 0;
aboutButton.onRollOver = function() {
duplicateMovieClip(SubAbout, "subAbout2", 10);
setProperty(subAbout2, _x, 0);
setProperty(subAbout2, _y, 33);
};
aboutButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subAbout2.removeMovieClip();
clearInterval(delayI);
}
//=======================
contactButton.onRollOver = function() {
duplicateMovieClip(SubContact, "subContact2", 10);
setProperty(subContact2, _x, 0);
setProperty(subContact2, _y, 33);
};
contactButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subContact2.removeMovieClip();
clearInterval(delayI);
}
//========================================
servicesButton.onRollOver = function() {
duplicateMovieClip(SubServices, "subServices2", 10);
setProperty(subServices2, _x, 0);
setProperty(subServices2, _y, 33);
};
servicesButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subServices2.removeMovieClip();
clearInterval(delayI);
}
//============================================
storeButton.onRollOver = function() {
duplicateMovieClip(SubStore, "subStore2", 10);
setProperty(subStore2, _x, 0);
setProperty(subStore2, _y, 33);
};
storeButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subStore2.removeMovieClip();
clearInterval(delayI);
}
//========================================
webtrackButton.onRollOver = function() {
duplicateMovieClip(SubWebtrack, "subWebtrack2", 10);
setProperty(subWebtrack2, _x, 0);
setProperty(subWebtrack2, _y, 33);
};
webtrackButton.onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000);
};
function delayF() {
subWebtrack2.removeMovieClip();
clearInterval(delayI);
}
stop();
MyFlashMXIN Guest
-
kglad #5
Re: getUTCMilliseconds() -vs.- setInterval
oops, i missed your _global.elapsedTime=0; statement. anyway, you don't need
to use elapsedTime with the code you have now. does the code you have now
work? if so, it can be considerably condensed by using an array and a for-loop
to define all your button events and functions.
kglad Guest
-
MyFlashMXIN #6
Re: getUTCMilliseconds() -vs.- setInterval
No it sure doesn't... It acts like the timer doesn't start now. The problem before was the timer would go nuts after a few rollOvers. Like it would loose count of the time passed...
MyFlashMXIN Guest
-
MyFlashMXIN #7
Re: getUTCMilliseconds() -vs.- setInterval
Here's the break down so far:
The original code worked the first time threw... After that the time delay
seems to loose time, delay goes to like 1 second if that... If you rollOver the
Main menu fast or more than once it goes APE "SH*T" :-)
I tried your code with and without the global... nothing happens, that is to
say the sub menus do not delay and then remove, they just sit there...
MyFlashMXIN Guest
-
kglad #8
Re: getUTCMilliseconds() -vs.- setInterval
it went wacky because you weren't using clearInterval() on rollover and were
initiating more intervals than you could clear. you're now having trouble
because you're using the same function name, delayF() to try and do different
things. anyway, convert your sub movie names (ie, SubServices etc) to lower
case (subservices etc) and try this:
buttonA = new Array("aboutButton", "contactButton", "servicesButton",
"storeButton", "webtrackButton");
for (ivar=0; ivar<buttonA.length; ivar++) {
_root[buttonA[ivar]].butNum = ivar;
_root[buttonA[ivar]].onRollOver = function() {
rclip = _root["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))];
sclip = rclip.duplicateMovieClip(String(["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))])+2, 10);
sclip._x = 0;
sclip._y = 33;
};
_root[buttonA[ivar]].onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000, sclip);
};
}
function delayF(mc) {
mc.removeMovieClip();
clearInterval(delayI);
}
kglad Guest
-
MyFlashMXIN #9
Re: getUTCMilliseconds() -vs.- setInterval
Damn! That works like a charm!
Okay I got to ask, why lowercase with all the MC's?
MyFlashMXIN Guest
-
MyFlashMXIN #10
Re: getUTCMilliseconds() -vs.- setInterval
Shoot! Forgot to ask, on 2 buttons I have no sub menu what AS would I use to flat remove the time to make the sub menu go away?
MyFlashMXIN Guest
-
kglad #11
Re: getUTCMilliseconds() -vs.- setInterval
well, it doesn't all have to be lower case. it would have been easy to make
the S in sub uppercase, but making subAbout is more difficult because i used
string methods on "aboutButton" to strip away Button leaving "about" and to
change the a to upper case would require another line of script and an
additional hassle.
and what two buttons have no submenu? is it one of the 5 about which we've
been talking? if not, then just don't duplicate a submenu for these, then you
don't have to remove the submenu.
kglad Guest
-
MyFlashMXIN #12
Re: getUTCMilliseconds() -vs.- setInterval
got an e-mail? I'd like to send you a copy so you can see it in action... (I'd
upload it but I've been asked not to now :-( )
the 2 buttons are not with the 5, they are totally independent... (just need
to force the 5 second delay to end)
one other thing that had slipped my mind before was to add AS to the sub menu
to hold the roll state of the menu button, I read another post of yours and it
said that you couldn't do it with buttons that you would have to use MC's.
could you show me a line of AS to add to the previous to call this? it would
need to hold the over state (frame 2) for the 5 sec. :-)
Thanks much!
MyFlashMXIN Guest
-
MyFlashMXIN #13
Re: getUTCMilliseconds() -vs.- setInterval
Okay, tried the add gotoAndPlay myself, but I'm lost! This has no effect...
Where did I go wrong?
//Stage.scaleMode = "noScale"
Stage.align = "TL";
_root.logo._width = 260.0;
_root.logo._height = 31.0;
myListener = new Object();
myListener.onResize = function() {
emergency._x = Stage.width-emergency._width;
statement._x = Stage.width-statement._width;
topTray._width = Stage.width;
};
Stage.addListener(myListener);
buttonA = new Array("aboutButton", "contactButton", "servicesButton",
"storeButton", "webtrackButton");
for (ivar=0; ivar<buttonA.length; ivar++) {
_root[buttonA[ivar]].butNum = ivar;
_root[buttonA[ivar]].onRollOver = function() {
_root[buttonA[ivar]].gotoAndPlay(2);
rclip = _root["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))];
sclip = rclip.duplicateMovieClip(String(["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))])+2, 10);
sclip._x = 0;
sclip._y = 33;
};
_root[buttonA[ivar]].onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000, sclip);
};
}
function delayF(mc) {
mc.removeMovieClip();
_root[buttonA[ivar]].gotoAndPlay(1);
clearInterval(delayI);
}
MyFlashMXIN Guest
-
kglad #14
Re: getUTCMilliseconds() -vs.- setInterval
the 5 second delay on the 5 buttons we've been working on, was a delay to
remove the submenu. if you have buttons that have no submenu, why are we
removing a submenu that doesn't exist and why are we delaying 5 seconds before
removing a submenu that doens't exist?
amend that code given above to:
buttonA = new Array("aboutButton", "contactButton", "servicesButton",
"storeButton", "webtrackButton");
for (ivar=0; ivar<buttonA.length; ivar++) {
_root[buttonA[ivar]].butNum = ivar;
_root[buttonA[ivar]].onRollOver = function() {
rclip = _root["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))];
sclip = rclip.duplicateMovieClip(String(["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))])+2, 10);
sclip.onRollOver=function(){
clearInterval(delayI);
}
sclip.onRollOut=function(){
this.removeMovieClip; //use this if you want immediate removal of a
submenu after it's experiences a rollOut
//delayI = setInterval(delayF, 5000, this); //use this if you want a 5
second delay in this menu's removal
}
sclip._x = 0;
sclip._y = 33;
};
_root[buttonA[ivar]].onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000, sclip);
};
}
function delayF(mc) {
mc.removeMovieClip();
clearInterval(delayI);
}
p.s. i'd rather not engage in flash help via email.
kglad Guest
-
MyFlashMXIN #15
Re: getUTCMilliseconds() -vs.- setInterval
Okay last question for me on this post: "I SWEAR!"
the menu MC instances all have 2 frames, is there a way to add a
gotoAndPlay(2) on the mouse over, and then return to (1) after the 5 seconds...
EX... If yourollOver "aboutButton" subabout MC shows for 5 sec, in addition
"aboutButton" goes to frame 2 of it's self and waits the same 5 sec... Then
after 5 sec or when the next "whateverButton" is rollOver "aboutButton" goes
back to frame 1....
In essance creating a rollOver effect for the main menu...
I sure appriciate all the help!
Thanks, and thanks in advance!
MyFlashMXIN Guest
-
kglad #16
Re: getUTCMilliseconds() -vs.- setInterval
try the following:
buttonA = new Array("aboutButton", "contactButton", "servicesButton",
"storeButton", "webtrackButton");
for (ivar=0; ivar<buttonA.length; ivar++) {
_root[buttonA[ivar]].butNum = ivar;
_root[buttonA[ivar]].onRollOver = function() {
this.gotoAndStop(2);
clearInterval(delay2I);
delay2I = setInterval(delay2, 5000, this);
for (jvar=0; jvar<buttonA.length; jvar++) {
if (jvar != this.butNum) {
_root[buttonA[jvar]].gotoAndStop(1);
}
}
rclip = _root["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))];
sclip = rclip.duplicateMovieClip(String(["sub"+buttonA[this.butNum].slice(0,
buttonA[this.butNum].indexOf("Button"))])+2, 10);
sclip.onRollOver = function() {
clearInterval(delayI);
};
sclip.onRollOut = function() {
this.removeMovieClip;
//use this if you want immediate removal of a submenu after it's
experiences a rollOut
//delayI = setInterval(delayF, 5000, this); //use this if you want a 5
second delay in this menu's removal
};
sclip._x = 0;
sclip._y = 33;
};
_root[buttonA[ivar]].onRollOut = function() {
clearInterval(delayI);
delayI = setInterval(delayF, 5000, sclip);
};
}
function delayF(mc) {
mc.removeMovieClip();
clearInterval(delayI);
}
function delay2F(mc) {
mc.gotoAndStop(1);
clearInterval(delay2I);
}
kglad Guest
-
MyFlashMXIN #17
Re: getUTCMilliseconds() -vs.- setInterval
Okay all good, except my links in the SubMenu MC's aren't working...?
Any thoughts?
MyFlashMXIN Guest
-
kglad #18
Re: getUTCMilliseconds() -vs.- setInterval
this.removeMovieClip should be this.removeMovieClip()
and buttons in the submenus won't work because we defined mouse events for
submenu which will intercept those button events. to remedy, we need to remove
mouse events for the submenus and add mouse events for the submenu buttons.
for example:
sclip.button1.onRollOver = function() {
clearInterval(delayI);
};
sclip.button1.onRollOut = function() {
this.removeMovieClip(); //if button1 is a button or
//_parent.removeMovieClip(); if button1 is a movieclip button
}
kglad Guest
-
MyFlashMXIN #19
Re: getUTCMilliseconds() -vs.- setInterval
Works great! Thanks again for all the help...
I'll be publishing around noon EST... if you want to see it in action at that time or later: www.rjbagan.com
MyFlashMXIN Guest



Reply With Quote

