[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Delay

Can anyone tell me if there is a way to delay the script such as this:

onClipEvent (load) {
     play();
     delay (50 seconds, true)
     stop();
}

im looking for a code and not an answer to this specific problem I want to use it alot, any help would be appreciated.
0
grantunwin
Asked:
grantunwin
  • 4
  • 4
  • 2
1 Solution
 
rascalpantsCommented:
there is no code in Flash to do this directly, but there are at least three work-a-rounds for creating a timed delay...

1. use a looping movieclip that increments a variable, and when the variable reaches a specific number, an action happens.

2. using the getTimer(); code and doing a bunch of complicated actionscript

3. call a javascript function on the html page that uses setTimeout() for a delay and pass the variable back into the movie...


I personally use the first solution, because it is simple and works perfectly for what I what...  


I am not sure why Macromedia did not include a setTimeout() function in MX, because it would be used constantly, and would get rid of this headache...

you would think a timeline based application would have a delay() function for simple coding purposes...  


rp

0
 
stef4sCommented:
can I send u a fla?
0
 
Saqib KhanSenior DeveloperCommented:
Yes I do agree with you rascalpants , I was wondering the same thing lately why Macromedia did not added setTimeout to their library. But They did Add 'setInterval'. I did not do any research on setInterval but I am sure it has somthing to do with time Delay's.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
stef4sCommented:
here is a solution

create a movie call it timer

frame 1 of timer mc.


var sDelay = 0;
var startTime = 0;
var callBackfn = "";
this._visible = false;
stop();

function StartTimer(milliseconds, callBack)
{
//     trace("start")
     sDelay = milliseconds;
     callBackfn = eval(callBack);
     startTime = getTimer();
     gotoAndPlay(2);
}


function checkTime()
{
//     trace(getTimer() - startTime + " " + sDelay)
     if (getTimer() - startTime >= sDelay)
     {
          callBackfn();
          gotoAndStop(1);
     }
}



frame 2:

checkTime()


frame 3:

checkTime()
gotoAndPlay(2);


place it on a timeline.

on the timeline:
timer must stretch from frame 1 to 2 (to allow the movie to load correctly)

frame 2:

stop();
timer.StartTimer(5000,"_root.endTimer");
function endTimer(){
     trace("end");
}

0
 
rascalpantsCommented:
you sure gave a lot for 20 points stef4s...

you must need to get your monthly 3,000  :)



rp
0
 
Saqib KhanSenior DeveloperCommented:
And I think grantunwin was looking for a simple and easy solution as well for 20 Points :)
0
 
rascalpantsCommented:
I guess I value my time a little more...

call me a Points Snob :)


grantunwin, you got a steal...


rp
0
 
stef4sCommented:
its not about points for me.

And pasting code into a text window is easy enough
0
 
rascalpantsCommented:
yeah, I guess if you already have the code written then it is pretty simple...
0
 
stef4sCommented:
grantunwin have you tried the solution?
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now