4 Replies Latest reply on Aug 25, 2006 9:08 PM by _gary_

    timer and action

    _gary_ Level 1
      Currently I have the first set of AS below that closes a window by clicking on a button. I would like to close the window automatically after 5 seconds have elapsed from the time the window is opened, the Last set of AS that is below is used to open the window. The middle set of AS is from a tutorial. I am needing help putting this all together.

      What i would like to happen is when the window is opened

      contact_btn.onPress = function(){
      contactLoader.load("contact.swf");
      }

      after 5 seconds the window closes using the tween close from the middle section below

      Thanks So Much for Helping in Advance


      close_btn.onPress = function(){
      new mx.transitions.Tween(_root.firstLoader.content.con tactLoader.content, "_alpha", mx.transitions.easing.Regular.easeOut, _root.firstLoader.content.contactLoader.content._a lpha, 0, 20);

      var interval:Number = 5;
      function someCodeToRun() {
      clearInterval(mySetInterval);
      trace(interval+" seconds have elapsed");
      }
      mySetInterval = setInterval(this, "someCodeToRun", interval*1000);

      contact_btn.onPress = function(){
      contactLoader.load("contact.swf");
      }
        • 1. Re: timer and action
          blemmo Level 1
          Just put the code that starts the interval inside the onRelease function too:

          contact_btn.onPress = function(){
          contactLoader.load("contact.swf");
          mySetInterval = setInterval(this._parent, "someCodeToRun", interval*1000); // 'this' inside onPress refers to the button
          }

          This starts the countdown as soon as the button is pressed, so the time it takes to load the MC will be a part of the 5 second interval. I don't know what 'contactLoader' is, if it is a MovieClipLoader, you could also start the interval inside the onLoadInit event, that way the 5 seconds will start after the clip was loaded.

          The event of the close button can be called from the interval function:

          function someCodeToRun() {
          clearInterval(mySetInterval);
          trace(interval+" seconds have elapsed");
          close_btn.onPress();
          }

          hth,
          blemmo
          • 2. Re: timer and action
            _gary_ Level 1
            i am doing something wrong when I insert the "SomeCodeToRun"

            how exactly should this line appear in the statement

            new mx.transitions.Tween(_root.firstLoader.content.con tactLoader.content, "_alpha", mx.transitions.easing.Regular.easeOut, _root.firstLoader.content.contactLoader.content._a lpha, 0, 20);

            thanks blemmo
            • 3. Re: timer and action
              blemmo Level 1
              I didn't use the Tween class yet, but there are some spaces in the posted code that shouldn't be there. Check if they are also in your code, might already be the problem.
              • 4. Re: timer and action
                _gary_ Level 1
                i came up with this

                var interval:Number = 5;
                function someCodeToRun() {
                clearInterval(mySetInterval);
                new mx.transitions.Tween(_root.firstLoader.content.contactLoader.content, "_alpha", mx.transitions.easing.Regular.easeOut, _root.firstLoader.content.contactLoader.content._alpha, 0, 20);
                trace(interval+" seconds have elapsed");
                }

                contact_btn.onPress = function(){
                contactLoader.load("contact.swf");
                mySetInterval = setInterval(this._parent, "someCodeToRun", interval*1000);
                }

                and it works great

                but it interferes with this

                var interval2:Number = 1;
                function someCodeToRun2() {
                clearInterval(mySetInterval2);
                trace(interval+" seconds have elapsed");
                imageLoader.load("port_bb_01.swf");
                nailLoader.load("nail_bb_01.swf");
                }

                ben_btn.onPress = function(){
                new mx.transitions.Tween(imageLoader.content, "_alpha", mx.transitions.easing.Regular.easeOut, imageLoader.content._alpha, 0, 20);
                new mx.transitions.Tween(nailLoader.content, "_alpha", mx.transitions.easing.Regular.easeOut, nailLoader.content._alpha, 0, 20);
                mySetInterval2 = setInterval(this._parent, "someCodeToRun2", interval*670);
                }

                How do I differentiate them. The time delay? The Variable Number?

                They both exist as AScript on the first frame of the top layer, along with other code as well.