A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Event set to timer

  1. #1
    yeah yeah yeah sandyrivers's Avatar
    Join Date
    Jul 2002
    Location
    Jibblies!
    Posts
    480

    Event set to timer

    I know this question has been asked before, but in my search of the tues and boards I didn't see anything that could help without rewriting all of my code, so I thought I'd ask first to see if there was an easy fix.

    I have a picture slideshow set to a button, that loads and shuffles an array of external .swfs into two MC holders and shows a fade transition between pics when the button is pressed. I'd like to remove the button script and replace it with a timed function that advances to the next swf after an amount of time has elapsed (say 30 seconds). Can someone help me modify my code? I haven't used timed events before.

    code:

    swfArray = new Array("pic1.swf", "pic2.swf", "pic3.swf");

    Array.prototype.shuffle = function() {
    for (var ivar = this.length-1; ivar>=0; ivar--) {
    var p = random(ivar+1);
    var t = this[ivar];
    this[ivar] = this[p];
    this[p] = t;
    }
    };
    ASSetPropFlags(Array.prototype, "shuffle", 1);

    swfArray.shuffle();

    this.createEmptyMovieClip("target1",1)
    this.createEmptyMovieClip("target2",2)

    target1.loadMovie(swfArray[0]);

    activeTarget = target1;
    currentIndex = 0;

    this.onEnterFrame = function() {
    currentIndex++;
    if(currentIndex>=swfArray.length) {
    currentIndex=0;
    swfArray.shuffle();
    }
    target1.loadMovie(swfArray[0]);
    }

    target2._alpha = 0;

    this.onEnterFrame = function() {
    if (obj1._alpha > 0) {
    obj1._alpha -= 10;
    }
    if (obj2._alpha < 100) {
    obj2._alpha += 10;
    }
    };

    //button script that swaps load target focus and loads the next movie
    nextButton.onRelease = function() {
    if (activeTarget == target1) {
    obj1 = target1;
    obj2 = activeTarget = target2;
    } else {
    obj1 = target2;
    obj2 = activeTarget = target1;
    }

    currentIndex++;
    if(currentIndex>=swfArray.length) {
    currentIndex=0;
    swfArray.shuffle();
    }
    this.loadMovie(swfArray[0]);

    obj2.loadMovie(swfArray[currentIndex])

    obj1.onEnterFrame = function () {
    if (this._alpha <=0 ) {
    this.unloadMovie();
    delete this.onEnterFrame;
    }
    }
    };



    Any help is appreciated!

    -Sandy

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    I didn't read through your code but you'll want to use a setInterval() command. It's basically a command that tells flash to run a function at set intervals. A couple important things to remember:
    1. It's not perfect, there are a lot of factors like frame rate, viewers processor speed, internet connection speed involved so you cannot set your watch by it but it's pretty darn close.

    2. Always assign your setInterval to a variable so that you can clear the interval later when your done with it.

    Here is the basic setup.

    if you have a function called nextSWF that you would like to call every 30 seconds:
    Code:
    function nextSWF(){
    //code for switching to the new swf
    }
    myInterval = setInterval(nextSWF, 30000); //1000 miliseconds = 1 second
    when you want to kill the interval you just use clearInterval on the variable you assinged the setInterval to.
    Code:
    clearInterval(myInterval);

  3. #3
    yeah yeah yeah sandyrivers's Avatar
    Join Date
    Jul 2002
    Location
    Jibblies!
    Posts
    480
    Got it. Thanks a lot!

    -Sandy

  4. #4
    yeah yeah yeah sandyrivers's Avatar
    Join Date
    Jul 2002
    Location
    Jibblies!
    Posts
    480
    OK follow up question:

    EDIT: I figured out my problem. My brain seemed to have checked out for a few minutes.

    Thanks!

    -Sandy
    Last edited by sandyrivers; 03-02-2006 at 05:17 PM.

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