A Flash Developer Resource Site

Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 68

Thread: MX setInterval Explained

  1. #21
    Member
    Join Date
    Mar 2000
    Location
    Madrid, Spain
    Posts
    51
    A thousand thanx! It now works, setting the close function, funcCierra, into the timed actions ...

    Now back to the subsection highlightning, and it's all done!

    Thanx for the help senocular! I'll always be in debt with you.
    Keep all those great tutorials coming!
    ..|..|..|..|..|..|..|..|..|..|..|..|..|
    TiMuN .. reasonably crazy spaniard jack-of-all-trades

  2. #22
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    Another brilliant sticky, senocular. Keep it up.

    Rick
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  3. #23
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    eeeerr... I never use components... but I think you mean the scrollPane component as the ScrollBar component is only for text.


    As far as I know, again I never use these things so Im not sure, anything you can do with a movieclip, you can do in a scroll component as its just a method for moving and positioning a movieclip within a scrollbar enabled rectangular viewing pane.

  4. #24
    Senior Member Ex-Ess's Avatar
    Join Date
    Nov 2002
    Location
    York (England)
    Posts
    588
    nice job. puzzled me for ages.

  5. #25
    SenoC is tha man

  6. #26
    Senior Member
    Join Date
    Apr 2003
    Location
    St. Louis
    Posts
    104
    hehe, I just used setInterval a few weeks ago for a dynamic menu that needed to scroll.

    Basically, I pull back a bunch of requests from the database and build a list that you could click on an item for more information. Obviously, this list could get long, so I made a scrolling menu out of it. I can adjust the interval to speed up, or slow down my menu.

    It works like a charm

    In order to keep multiple intervals from being set when a person rapidly clicks on the up or down button, even though I may have clearInterval on the Release (it still occured). I placed the If statement in there, that way, the release has to occur, removing the interval before another one can be created.

    edit: hehe, hopefully noone saw that, I think ill make a tutorial out of it.

    _root.contentArea.scroll_down.onPress = function () { // moves data up the screen
    if (_root.scrollingDataDown != 1) {
    _root.scrollingDataDown = 1;
    scrollReturnedBars = setInterval( scrollCommands, 80 )
    }
    }
    _root.contentArea.scroll_down.onRelease = function () {
    _root.scrollingDataDown = 0;
    clearInterval( scrollReturnedBars )
    }
    _root.contentArea.scroll_up.onPress = function () { // moves the data back down the screen
    if (_root.scrollingDataUp != 1) {
    _root.scrollingDataUp = 1;
    scrollReturnedBars = setInterval( scrollCommands, 80 )
    }
    }
    _root.contentArea.scroll_up.onRelease = function () {
    _root.scrollingDataUp = 0;
    clearInterval( scrollReturnedBars )
    }
    Last edited by StunnedGrowth; 04-10-2003 at 07:39 PM.
    Ben

  7. #27
    Junior Member
    Join Date
    Sep 2002
    Posts
    7

    Coolies

    This makes loads of things possible now that I couldn't do before. Thanks so much.

    ____________________
    Blazin
    www.manysecrets.com

  8. #28
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449

    interval in onclip events

    Hi,

    since this thread is about intervals, I would like to contribute something I recently found answering somebody's problem. Here is a script to control onClip Events in movieclips:

    PHP Code:
    onClipEvent (load) {
        
    c=1;//defining the initial value of var c.
    }

    onClipEvent (enterFrame) {
        if (
    == 10){//this is the interval frequency
       
    trace("it is working!");
            
    c=1;//reset var to original value
        
    }
        
    c++;//increment c

    - The right of the People to create Flash movies shall not be infringed. -

  9. #29
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361

    Re: interval in onclip events

    Thanks for the input cancerinform

    Id suggest the following altercation to the code
    PHP Code:
    onClipEvent (load) {
        
    c=1// defining the initial value of var c.
    }

    onClipEvent (enterFrame) {
        if (
    == 10){ // this is the interval frequency
            
    trace("it is working!");
            
    c=1// reset var to original value
        
    }else{
            
    c++; // increment c
        
    }

    The change is putting the c++ in the else of the if statement. This is because, if its not, after you set c back to 1 when c is 10, c++ gets called again and is actually 2 instead of 1. Now, if c is 10, the c++ wont be called and it will stay 1 until the next frame where its checked again

  10. #30
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Well done, I haven' noticed that. I was too impatient.
    - The right of the People to create Flash movies shall not be infringed. -

  11. #31
    Junior Member
    Join Date
    Jun 2003
    Posts
    19
    Thanks for the information Senocular, I have read your article several times and still don't quite get it all. I'm working on it though...

    I did run into something that was not discussed in your article nor in the Flash reference and wondered if you had either encountered it or worked with it yourself. My question pertains to passing multiple variables to the function being called by a setInterval. Let me give you an example, here is the typical usage:

    Code:
    timer = setInterval(myObj, "myObjMeth", 1000, passThis1);
    However, as I often do with my functions, I need to pass more then one item to the function being called. Here is how I have tried it (although I have tried other ways, this seems to make the most sense):

    Code:
    timer = setInterval(myObj, "myObjMeth", 1000, (passThis1, passThis2));
    Unfortunately, I haven't had much luck with this. Any ideas on how to pass multiple variables through the setInterval?

  12. #32
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    just pass them as more arguemnts

    timer = setInterval(myObj, "myObjMeth", 1000, passThis1, passThis2, passThis3... etc.);

  13. #33
    Multimedia Developer
    Join Date
    Jun 2001
    Location
    Ireland
    Posts
    41
    excellent article, seems straight forward enough! its nice to see some MX specific issues covered in detail, i'm sure a lot of people here like myself are migrating to MX from 5 and so its often that we havent learnt all the new features in depth as yet. From a flash games point of view, setInterval() is brilliant for writing timers with no fuss.

    cheers
    Just cos you're paranoid, does'nt mean that they aint out to get you

  14. #34
    Member
    Join Date
    Jul 2003
    Location
    Bozeman, MT USA
    Posts
    32
    I know you said not to set any watches, but have you found a specific fps that dials you in at the setInterval rate you were looking for? If not, how would you create a timer or a counter... even as an app. Do you have to use system time? Or is there another ingenious way of doing it?

    Really want to know, thanks.

    -D
    "I'm an idiot"

  15. #35

    another for the setInterval experts

    thanks for all of the amazing code thus far. i believe i have a decent handle on how to use setInterval in a standard context, but i am working on an XML fed array to plot points on a map. the following code works well, but plots all of the points at once. what i would like to try to do is implement a delay after each item [i] is populated until all of the [i]s are done. this way the population will flow in over time rather than all at once. any ideas where to implement the code into this? :



    // XML load successful
    if (gXML.hasChildNodes()) {

    //pull in list
    listnode=gXML.firstChild;

    //load description (children of main node)
    if(listnode.hasChildNodes()){

    var i =0;
    var project = listnode.firstChild;
    while(project != null){
    trace(project.attributes.id);

    name = "icon" + i;
    //attach an item button for each item
    this.attachMovie("icon",name,i);
    //set the button attributes (name and id)

    this[name].title = project.attributes.title;
    this[name].location = project.attributes.location;
    this[name].id = project.attributes.id;
    //display the button
    this[name].gotoAndPlay("display");

    //set its position
    this[name]._x = project.attributes.location_mapx;
    this[name]._y = project.attributes.location_mapy;
    this.list[i] = project;
    project = project.nextSibling;

    i++;

    }

    }




    }
    stop();
    Last edited by morican; 08-08-2003 at 05:14 PM.

  16. #36
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Originally posted by circuitbored
    excellent article, seems straight forward enough! its nice to see some MX specific issues covered in detail, i'm sure a lot of people here like myself are migrating to MX from 5 and so its often that we havent learnt all the new features in depth as yet. From a flash games point of view, setInterval() is brilliant for writing timers with no fuss.

    cheers
    I never use setInterval or any time specific calculations in games. The reason for this is, if your game is time-sensitive, something such as a racing game where lap times count, people with slower computers will have a disadvantage because they wont be able to keep the FPS up meaning they wont get as many frames out of a given time period meaning they essentially wont be going as fast, even though, in comparison to the movie playing itself, ie. the 'enemy' cars, a player playing at that lower FPS can still win as the rate of movement of those other cars is similarly reduced. Time, however, is not. Its steady and constant despite the rate of speed of the movie. Now when I say time I mean something like getTimer or Date, as setInterval is not exact in terms of time. Its more of an approximation. So thats another hit for using setInterval as a timer in a game environment. I always base a timer on an enterFrame event which assures consistant timing throughout all frame rates.

  17. #37
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Ok,

    Senocular doesn't like components. May be you like this one. It's just convenient. Here is a little thing, which allows you to pause in a frame for a defined time and then go to another frame. Just open the fla file and put the component into the movie you work and then put it in the frame you want to pause. Click on it and enter the frame name you want to go after the pause and the time you want to pause. Default here is 5 sec. If you find it does not work, let me know. I tested it in a complex movie, which has other components.
    - The right of the People to create Flash movies shall not be infringed. -

  18. #38
    Junior Member
    Join Date
    Apr 2003
    Location
    Oklahoma - USA
    Posts
    5

    newbie w/ questions here

    I admit that I am in over my head, but here is my question:
    How can I load a movie and set the interval to only run so many seconds?

    I tried something like this:

    mymovie.loadMovie("Typewriter-mine01.swf",_root);
    setInterval(mymovie,30000);

  19. #39
    Registered User
    Join Date
    Dec 2003
    Location
    Always from The Bronx
    Posts
    2

    Re: MX setInterval Explained

    [QUOTE]Originally posted by senocular
    [B]I did this one tonight at the request of Jaffasoft
    Im a little tired so I hope there arent TOO many mistakes heh. And I didnt include an Appendix as I did with ASBroadcaster, though I dont think theres really as much you can do to extend the use of setInterval. The applications section give some basic usage. Should be a pretty decent go through on the function though:

    http://www.umbc.edu/interactive/flas...?p=setInterval

    ---------------------------------

    Cenocular,

    When I tried using the following script in your turorial I received an error. I must be doing something wrong.

    Error::::
    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: Statement must appear within on handler
    displayTime=30;

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 3: Operator '-' must be followed by an operand
    displayTime-;

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 2: Statement must appear within on handler
    countDown=function(message){

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 9: Statement must appear within on handler
    timer=setInterval(countDown, 1000);

    Ginns

  20. #40
    Registered User
    Join Date
    Dec 2003
    Location
    Always from The Bronx
    Posts
    2

    Opps

    Guys,

    My bust. I forgot to call the function. I feel dumb.

    Ginns

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