15 Replies Latest reply on Aug 25, 2010 9:35 PM by kglad

    setting time to load mc

    dn0myar06

      i am creating a game that will load mangoes with numbers on it....i'm using numbers -9 to 9

      i  would like to set the time of each mango to load...for example: #2  mango loads every 48th and 15th second of the time, #-5 mango loads  every 38th, 15th, 3rd second of the time left....how do I code that???

       

      i have a code that loads the mangoes in random x position...but when the character caught the mango, it doesn't load again...

      here's a jpg of what i'm trying to do...

       

      khigh game5 - page1.jpg

       

      this is the code i'm using: this code is attached in the (-2) mango

       

      onClipEvent (load) {

       

      //if (_root.time == 50) {   ----------------> i tried to put an if statementto determine the loading time but doesn't work

       

          function reset() {

              this._x=random(550);

              this._y=-250;

             _root.speedb=-5;

          }

          reset();

      //}

      }

       

      onClipEvent (enterFrame) {

      //if (_root.time == 50) {  ------------------------>i also tried to put it here but doesn't work too...

          this._y-=_root.speedb;

          if (_y > 380) {

              reset();

              }

           if  (_root.mango_mc.inMango_mc.hitTest(_root.caloy_LR.caloy_Right.inBaske  t_mc) ||  _root.mango_mc.inMango_mc.hitTest(_root.caloy_LR.caloy_Left.inBasket_  mc) ||  _root.mango_mc.inMango_mc.hitTest(_root.caloy_LR.caloy_stop.inBasket_  mc)) {

              _parent.mango_mc.gotoAndPlay(2);

              _root.score -=2;

          }

      //}

      }

       

      Hope you guys could help...thanks!!!!

        • 1. Re: setting time to load mc
          kglad Adobe Community Professional & MVP

          remove that code from the mango movieclip and attach the analagous code to the mango's timeline:

           


                  this._x=random(550);

                  this._y=-250;

          speedb=-5;


           

          this.onEnterFrame=function(){
          this._y-=speedb;

              if (_y > 380) {

            this.removeMovieClip();

                  }

               if  (this.hitTest(_root.caloy_LR.caloy_Right.inBaske   t_mc) ||  this.hitTest(_root.caloy_LR.caloy_Left.inBasket_   mc) ||  this.hitTest(_root.caloy_LR.caloy_stop.inBasket_   mc)) {

                  this.gotoAndPlay(2);

                  _root.score -=2;

              }

          //}

          }

           

          }

           

          then right click on your mango movieclip in your library, click linkage, tick export for actionscript and assign a linkage id (eg, mangoID).  once you've done that you're setup to do the rest.

          • 2. Re: setting time to load mc
            dn0myar06 Level 1

            its not working...the mango doesn't fall at all...

             

            this is the code that i paste to the mango timeline:

             

            if (_root.time == 50) {
                    mango12._x=random(550);         //mango12 is what i used in the linkage
                    mango12._y=-250;
                    _root.speedb=-5;
               
                mango12.onEnterFrame=function() {
                mango12_mc._y-=_root.speedb;
                if (_y > 380) {
                    reset();
                    }
                if (_root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_Right.inBasket_mc) || _root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_Left.inBasket_mc) || _root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_stop.inBasket_mc)) {
                    _parent.mango12_mc.gotoAndPlay(2);
                    _root.score -=2;

             

              }
            }

            • 3. Re: setting time to load mc
              dn0myar06 Level 1

              the first code that i was using was working until I put the "if statement" that will set the loading time of the mango mc...

               

              i also tried to remove the if statement in the load...and put it in the enterframe handler...it's quite working but the position of the mango went on the way up and the falling includes about 200px only...

              • 4. Re: setting time to load mc
                kglad Adobe Community Professional & MVP

                use this code on the mango timeline.:

                 


                        this._x=random(550);

                        this._y=0

                speedb=-5;


                 

                this.onEnterFrame=function(){
                this._y-=speedb;

                    if (_y > Stage.height) {

                  this.removeMovieClip();

                        }

                      if  (this.hitTest(_root.caloy_LR.caloy_Right.inBaske   t_mc) ||   this.hitTest(_root.caloy_LR.caloy_Left.inBasket_   mc) ||   this.hitTest(_root.caloy_LR.caloy_stop.inBasket_   mc)) {

                        this.gotoAndPlay(2);

                        _root.score -=2;

                    }

                //}

                }

                 

                }

                 

                 

                don't place any mango's on-stage.  use attachMovie() to create mango instances:

                 

                on your main timeline:

                 

                var tl:MovieClip=this;

                var dep:Number=0;

                tl.attachMovie("mangoID","mango_"+dep,dep++);

                 

                and to create these mango instances every 30 seconds use:


                var mangoI=setInterval(mangoF,30000);


                function mangoF(){

                tl.attachMovie("mangoID","mango_"+dep,dep++);

                }

                • 5. Re: setting time to load mc
                  dn0myar06 Level 1

                  now the mangoes are falling again but the interval is not working...it only loads at the beginning, then afte 30 sec. nothing...

                   

                  and about my hitTest...i created a small movieclip at the bottom of the mango and set the alpha to 0...when i used the code that you gave me, the whole mango itself is the one performing the hitTest, not the mc that I created...

                  i used my old target for the hitTest but it doesn't work

                   

                  if  (_root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_Right.inBasket_mc) || _root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_Left.inBasket_mc) || _root.mango12.inMango_mc.hitTest(_root.caloy_LR.caloy_stop.inBasket_mc)) {

                   

                  //mango12 is also the name of the identifier in the linkage

                  //inMango_mc is the small mc below the mango

                  • 6. Re: setting time to load mc
                    dn0myar06 Level 1

                    ow..i've solved my hitTest problem

                     

                    i used this code:

                     

                    if  (this.inMango_mc.hitTest(_root.caloy_LR.caloy_Right.inBasket_mc) || this.inMango_mc.hitTest(_root.caloy_LR.caloy_Left.inBasket_mc) || this.inMango_mc.hitTest(_root.caloy_LR.caloy_stop.inBasket_mc)) {

                     

                     

                     

                    now my only problem is the interval of the mangoes...may i know what the 30000 is for??

                    or the parameters for the interval??

                    • 7. Re: setting time to load mc
                      kglad Adobe Community Professional & MVP

                      setInterval() calls mangoF every 30000 milliseconds (=30 seconds) and if you assign the linkage id correctly, that would create a new mango every 30 seconds.

                      1 person found this helpful
                      • 8. Re: setting time to load mc
                        dn0myar06 Level 1

                        ey thanks...

                         

                        but how can i set the loading time of the mangoes...for example, mango with value +3 will only show on the 25th second left on time??

                        is it possible??

                         

                         

                        and how will i use the code for the other mangoes?

                        should i just copy paste the code and replace the mangoID??

                         

                        var tl:MovieClip=this;
                        var dep:Number=0;
                        tl.attachMovie("mango12","mango_"+dep,dep++);    //should i just replace the mangoID here, and copy paste everything?

                         

                        var mangoI=setInterval(mangoF,30000);     //if I retain this, will all the mangoes load every 30 sec??

                         

                        function mangoF(){
                        tl.attachMovie("mango12","mango_"+dep,dep++);     //same here??
                        }

                         

                        //i actually have 18 mangoes, from -9 to +9 but no mango with 0 value

                        //the code you gave me works perfectly for 1 mango..i'm just not sure how to use it to the other mangoes...

                        and thanks for the code again..i appreciate it...

                        • 9. Re: setting time to load mc
                          kglad Adobe Community Professional & MVP

                          here's how to create two mangos, mango12 and mango 13:

                           

                          var tl:MovieClip=this;
                          var dep:Number=0;
                          tl.attachMovie("mango12","mango_"+dep,dep++);  

                          tl.attachMovie("mango13","mango_"+dep,dep++);  

                           

                          var mangoI12=setInterval(mangoF12,30000);     //if I retain this, will all the mangoes load every 30 sec?? - no, just mango12

                          var mangoI13=setInterval(mangoF13,45000);     // mango13 is created every 45 seconds

                           

                           

                          function mangoF12(){
                          tl.attachMovie("mango12","mango_"+dep,dep++);   
                          }


                          function mangoF13(){

                          tl.attachMovie("mango13","mango_"+dep,dep++);   

                          }

                          • 10. Re: setting time to load mc
                            dn0myar06 Level 1

                            thanks kglad!!!

                             

                            how can i remove all mango mc when score is equivalent to target score???

                            i put this code to my mango mc but doesn't work:

                             

                                if (_root.score == _root.tar) {
                                this.removeMovieClip();
                                }

                             

                            i tried this code to my timeline but doesn't work as well:

                             

                                if (_root.score == _root.tar) {
                                     _parent.mango1.gotoAndPlay(2);   //where frame 2 of mango mc has a removeMovieClip as well

                                 }

                             

                            any idea??

                            • 11. Re: setting time to load mc
                              kglad Adobe Community Professional & MVP

                              use an array to store your mango references.  when you want to remove the mangos, loop through the array looking for references that still exist:

                               

                              var mangoA:Array=[];

                               

                               

                              .

                              .

                              .

                              // whenever a mango is created, add it to mangoA

                              var mango:MovieClip=tl.attachMovie(etc ...);

                              mangoA.push(mango);

                               

                              .

                              .

                              //when you want to remove mangos:

                               

                              function removeAllF():Void{

                              for(var i:Number=0;i<mangoA.length;i++){

                              if(mangoA[i]){

                              mangoA[i].removeMovieClip();

                              }

                              }

                              mangoA=[];

                              }

                              • 12. Re: setting time to load mc
                                dn0myar06 Level 1

                                i haven't don array for a long time...maybe you could give me an idea on how to use it here in this code:

                                 

                                var tl:MovieClip=this;
                                var dep:Number=0;
                                tl.attachMovie("mango12","mango_"+dep,dep++);
                                tl.attachMovie("mango2","mango_"+dep,dep++);
                                tl.attachMovie("mango3","mango_"+dep,dep++);
                                tl.attachMovie("mango4","mango_"+dep,dep++);
                                tl.attachMovie("mango5","mango_"+dep,dep++);
                                tl.attachMovie("mango6","mango_"+dep,dep++);
                                tl.attachMovie("mango7","mango_"+dep,dep++);
                                tl.attachMovie("mango8","mango_"+dep,dep++);
                                tl.attachMovie("mango9","mango_"+dep,dep++);
                                tl.attachMovie("mango11","mango_"+dep,dep++);
                                tl.attachMovie("mango13","mango_"+dep,dep++);
                                tl.attachMovie("mango14","mango_"+dep,dep++);
                                tl.attachMovie("mango15","mango_"+dep,dep++);
                                tl.attachMovie("mango16","mango_"+dep,dep++);
                                tl.attachMovie("mango17","mango_"+dep,dep++);
                                tl.attachMovie("mango18","mango_"+dep,dep++);
                                tl.attachMovie("mango19","mango_"+dep,dep++);

                                 

                                var mangoI12=setInterval(mangoF12,8000);
                                var mangoI1=setInterval(mangoF1,5000);
                                var mangoI2=setInterval(mangoF2,5000);
                                var mangoI3=setInterval(mangoF3,5000);
                                var mangoI4=setInterval(mangoF4,9000);
                                var mangoI5=setInterval(mangoF5,4000);
                                var mangoI6=setInterval(mangoF6,3000);
                                var mangoI7=setInterval(mangoF7,15000);
                                var mangoI8=setInterval(mangoF8,25000);
                                var mangoI9=setInterval(mangoF9,15000);
                                var mangoI11=setInterval(mangoF11,10000);
                                var mangoI13=setInterval(mangoF13,9000);
                                var mangoI14=setInterval(mangoF14,15000);
                                var mangoI15=setInterval(mangoF15,5000);
                                var mangoI16=setInterval(mangoF16,6000);
                                var mangoI17=setInterval(mangoF17,15000);
                                var mangoI18=setInterval(mangoF18,7000);
                                var mangoI19=setInterval(mangoF19,15000);

                                 

                                function mangoF12(){
                                tl.attachMovie("mango12","mango_"+dep,dep++);
                                }

                                 

                                function mangoF1(){
                                tl.attachMovie("mango1","mango_"+dep,dep++);
                                }

                                 

                                function mangoF2(){
                                tl.attachMovie("mango2","mango_"+dep,dep++);
                                }

                                 

                                function mangoF3(){
                                tl.attachMovie("mango3","mango_"+dep,dep++);
                                }

                                 

                                function mangoF4(){
                                tl.attachMovie("mango4","mango_"+dep,dep++);
                                }

                                 

                                function mangoF5(){
                                tl.attachMovie("mango5","mango_"+dep,dep++);
                                }

                                 

                                function mangoF6(){
                                tl.attachMovie("mango6","mango_"+dep,dep++);
                                }

                                 

                                function mangoF7(){
                                tl.attachMovie("mango7","mango_"+dep,dep++);
                                }

                                 

                                function mangoF8(){
                                tl.attachMovie("mango8","mango_"+dep,dep++);
                                }

                                 

                                function mangoF9(){
                                tl.attachMovie("mango9","mango_"+dep,dep++);
                                }

                                 

                                function mangoF11(){
                                tl.attachMovie("mango11","mango_"+dep,dep++);
                                }

                                 

                                function mangoF13(){
                                tl.attachMovie("mango13","mango_"+dep,dep++);
                                }

                                 

                                function mangoF14(){
                                tl.attachMovie("mango14","mango_"+dep,dep++);
                                }

                                 

                                function mangoF15(){
                                tl.attachMovie("mango15","mango_"+dep,dep++);
                                }

                                 

                                function mangoF16(){
                                tl.attachMovie("mango16","mango_"+dep,dep++);
                                }

                                 

                                function mangoF17(){
                                tl.attachMovie("mango17","mango_"+dep,dep++);
                                }

                                 

                                function mangoF18(){
                                tl.attachMovie("mango18","mango_"+dep,dep++);
                                }

                                 

                                function mangoF19(){
                                tl.attachMovie("mango19","mango_"+dep,dep++);
                                }

                                stop();

                                • 13. Re: setting time to load mc
                                  kglad Adobe Community Professional & MVP

                                  all your code can be replaced with the following:

                                   


                                   

                                  stop();


                                  var tl:MovieClip=this;
                                  var dep:Number=0;

                                  var mangoA:Array = [];

                                   

                                  var setIntervalA:Array = [5000,5000,5000,9000,4000,3000,15000,25000,15000,10000, etc];

                                   

                                  for(var i:Number=1;i<=19;i++){

                                  tl["mango"+i] = setInterval(mangoF,setIntervalA[i],i);

                                  mangoF(i);

                                  }

                                   

                                  function mangoF(i:Number){

                                  var mango:MovieClip = tl.attachMovie("mango"+i,"mango_"+dep,dep++);

                                  mangoA.push(mango);

                                  }


                                  1 person found this helpful
                                  • 14. Re: setting time to load mc
                                    dn0myar06 Level 1

                                    its working..thanks!!!

                                     

                                    the only problem is, the mangoes still kept on loading...even if i used the removeAll function...

                                    • 15. Re: setting time to load mc
                                      kglad Adobe Community Professional & MVP

                                      when you want to stop creating new mangos, call the following function:

                                       


                                      function stopMangoF(){

                                      for(var i:Number=1;i<=19;i++){

                                      clearInterval(tl["mango"+i]);

                                      }

                                      }