A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Perform action after random time ?

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    Perform action after random time ?

    what i want is the mc to perform so actions after the random time which is chosen. So just say the random time is 10 seconds, the mc will wait 10 seconds before it will perform the actions. I just cant get the getTimer(); to work.

    would anyone have a good way to do this

    Thanks in AdvancE

    [h]ooligan

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    if Flash MX:

    myDelay=Math.floor(8*(Math.random())+1.5)*1000 // random numeber between 9-1. change accordingly


    myInterval=setInterval(doAction,myDelay,_root.myMo vieClip)

    function doAction(MC)
    {
    clearInterval(myInterval)

    //put action code here i.e.
    MC.gotoAndPlay(3)
    }


    if Flash 5:

    1 Frame loop
    Frame1:

    D_Time=Math.floor(8*(Math.random())+1.5)*1000
    StartTime=getTimer()

    Frame 2:
    Play()


    Frame 3:

    Time_Elapsed = (getTimer () - SoundStart)/1000;
    if (Time_Elapsed >= D_Time) {
    play ();
    } else {
    prevFrame ();
    }


    hope that helps

  3. #3
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks for that

    Would you possibly be able to explain wht the lines of code do in the MX version. im taking notes

    PS will this continue to do the same thing , because i only want it to wait that time and perform it once

  4. #4
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    I just tried but it wouldnt work , the only actions i changed where the gototAndPlay(2); to _y += 10;

    ??

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    myDelay=Math.floor(8*(Math.random())+1.5)*1000 // random numeber between 9-1. change accordingly. *1000 gives a value in milliseconds


    myInterval=setInterval(doAction,myDelay,_root.myMo vieClip)
    //create an interval of milliseconds (myDelay) and Call function (doAction) after interval duration. Pass the Name of the Clip to be targeted (_root.myMovieClip) to the function called


    //function called after Interval
    function doAction(MC)
    {
    //delete the Interval so not called again
    clearInterval(myInterval)

    //put action code here i.e.
    //target MovieClip via function parameter MC
    MC.gotoAndPlay(3)
    }



    hope that makes more sense.

  6. #6
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    thanks Jayhoo you have been a great help

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