Matching Frame Numbers on movie clips

  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

Okay so here's the deal: I have 4 of the same movie clips dragged onto the stage. The clip plays a movie that has a box changing different colors. There's also code in the movie clips that makes it go to random frames so not all the movie clips on the stage will play the same even though they derive from the same movie clip. In my main timeline I just have two frames, but it has script that makes it stopped on the first frame. I want to be able to have my code tell when all the four movie clips are on the same frame (frame 200), and when they are go to frame 2 on the main timeline.

I dont know if my explanation was too difficult but if you want me to provide an fla of what I have so far I can. I'm trying to use _currentframe.

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Welcome To Ozzu C360 :D

Try this in your main timeline right before the stop();

Code: [ Select ]
_root.onEnterFrame = function(){
    if(mC1._currentframe==200 && mC2._currentframe==200 && mC3._currentframe==200 && mC4._currentframe==200){
        play();
        delete _root.onEnterFrame;
    }
}
stop();
  1. _root.onEnterFrame = function(){
  2.     if(mC1._currentframe==200 && mC2._currentframe==200 && mC3._currentframe==200 && mC4._currentframe==200){
  3.         play();
  4.         delete _root.onEnterFrame;
  5.     }
  6. }
  7. stop();


Replace mC# with your movieClips instanceNames.
make sure there is a stop(); in the second frame or this will loop endlessly.
  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

There's no explaining how much I love you. I would like to know a lot more about you and how you came up with this solution so fast. You saved me additional hours. I've already spent hours upon hours trying to figure this out! I shall show you my "game" when I'm finished.\

Edit: I'm trying to do one more thing. I'm trying to define a range a frames. I want it to be if its from frame 200 to 300 instead of just frame 200. I tried >=200<300 but it looks to be using both too litterally.
  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

I did it now. I don't know if it's the best way but here it is.

Code: [ Select ]
_root.onEnterFrame = function(){
  if(_root.block1._currentframe>=200 && _root.block1._currentframe<=300 && _root.block2._currentframe>=200 && _root.block2._currentframe<=300 && _root.block3._currentframe>=200 && _root.block3._currentframe<=300 && _root.block4._currentframe>=200 && _root.block4._currentframe<=300){
   gotoAndPlay(3);
   delete _root.onEnterFrame;
  }
}
stop();
  1. _root.onEnterFrame = function(){
  2.   if(_root.block1._currentframe>=200 && _root.block1._currentframe<=300 && _root.block2._currentframe>=200 && _root.block2._currentframe<=300 && _root.block3._currentframe>=200 && _root.block3._currentframe<=300 && _root.block4._currentframe>=200 && _root.block4._currentframe<=300){
  3.    gotoAndPlay(3);
  4.    delete _root.onEnterFrame;
  5.   }
  6. }
  7. stop();
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

:D Glad I could help.
Reading & trying devolop speed. (more trying than reading) Whenever you have nothing to do just open a new movie and play around, it's not like you can break anything if there isn't a project depending on it :wink: Also, a few good names to remember in Flash, "lostinbeta, digitalMedia, unflux, voetsjoeba, sencular" not necisarily in that order but none the less I've learned a great deal from posts by them.
  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

Awesome, thanks.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Havent tested this one,
Code: [ Select ]
_root.onEnterFrame = function(){
    count = 0;
    for(i=1; i<5; i++){
        if(_root["block"+i]._currentframe>=200 && _root["block"+i]._currentframe<=300){
            count++;
        }
    }
    count==4 ? (gotoAndPlay(3), delete count, delete _root.onEnterFrame) : null;
}
  1. _root.onEnterFrame = function(){
  2.     count = 0;
  3.     for(i=1; i<5; i++){
  4.         if(_root["block"+i]._currentframe>=200 && _root["block"+i]._currentframe<=300){
  5.             count++;
  6.         }
  7.     }
  8.     count==4 ? (gotoAndPlay(3), delete count, delete _root.onEnterFrame) : null;
  9. }

Ought to do the trick though :D

EDIT // I forgot to switch a variable name earlier :oops:
  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

Here it is..

http://www.buzzybeetle.net/discofloor.html

I haven't used the new code you just posted. Still lookin at that..

However, the code you posted beforehand has helped me out a huuuge deal. I don't think I used it in it's tidiest possible way, but it worked! I only run into one problem: when a level starts up all the blocks may be the same color and the level ends. This only happens with the first level in a section, and after that it's it fat chance it will happen.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Code: [ Select ]
count = 0;
This keeps track of how many movieClips _currentframe is 200-300, the first time the code is run it initializes it at zero, each time after that it is reseting it to zero.

Code: [ Select ]
    for(i=1; i<5; i++){
        if(_root["block"+i]._currentframe>=200 && _root["block"+i]._currentframe<=300){
            count++;
        }
  1.     for(i=1; i<5; i++){
  2.         if(_root["block"+i]._currentframe>=200 && _root["block"+i]._currentframe<=300){
  3.             count++;
  4.         }
This is probably the first thing yor still looking at.
_root["block"+i] is referencing a movieclip in _root, puting the string "block" & the number that i is at in the loop together making a new string that is seen by Flash as the instanceName of a movieClip, an object or a variable.
you can also use this["firstPart" + variable] & _parent["firstPart" + variable] the same way. The only difference between the three is where Flash will start looking for the clip/variable/object.
So if our loop is at 3 then _root["block"+i]._currentframe is seen as _root.block3._currentframe by Flash.
count++ is just adding 1 to the number of movieClips that return true to the "if" statement.

This next part would have had me scratching my head awhile ago, it's called a "tertiary" & lostinbeta gives a most exelent explaination Here (halfway through 6th post)

Basically this,
Code: [ Select ]
count==4 ? (gotoAndPlay(3), delete count, delete _root.onEnterFrame) : null;

translates to this,
Code: [ Select ]
if(count==4){
  gotoAndPlay(3);
  delete count;
  delete _root.onEnterFrame;
}else{
  null; // do nothing except start this code all overagain untill count is==4
  1. if(count==4){
  2.   gotoAndPlay(3);
  3.   delete count;
  4.   delete _root.onEnterFrame;
  5. }else{
  6.   null; // do nothing except start this code all overagain untill count is==4



As for the movieclips all being the same color once in awhile i'm guessing you have no conditional statement in your randomization function.
Somthing close to this should fix it,
Code: [ Select ]
average = (randomValue1 + randomValue2 + randomValue3 + randomValue4) / 4;
if(average==randomValue1 && average==randomValue2 && ..rest of vals){
  randomValue1=3;
  randomValue3=1;
  delete average;
}
  1. average = (randomValue1 + randomValue2 + randomValue3 + randomValue4) / 4;
  2. if(average==randomValue1 && average==randomValue2 && ..rest of vals){
  3.   randomValue1=3;
  4.   randomValue3=1;
  5.   delete average;
  6. }

This finds an average of all values, if the average is equal to every one of them by themself then they are all the same, if they are all the same it rewrites values 1 & 3 to 3 & 1 leaving 2 & 4 as they are ensuring that all of the cubes random values will never be the same.

Your game kinda reminds me of a Rubix Cube :P
  • C360
  • Novice
  • Novice
  • C360
  • Posts: 23

Post 3+ Months Ago

Hey, sorry I haven't posted on this for a while. I got a little busy with some things. I'll implement what you showed me then I'll show it to you again. Thanks a lot!

Another thing: How busy are you? It seems that concepts of programming come really natural to you, and I was wondering if you'd like to help me out with a game. The animator Bryan Waterman is going to make graphics cut scenes for the game. He makes the Cartoon "Waterman" at http://www.watermanstudios.com I make the website!
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Why not have a variable on the root timeline that holds a value, and adjust that value through AS on frame 200 of the movieclip?

Example...

Frame on _root timeline has something like
Code: [ Select ]
var hitLast;
this.onEnterFrame = function(){
  if(hitLast>=4){
    gotoAndPlay(2);
    delete this.onEnterFrame;
  }
}
  1. var hitLast;
  2. this.onEnterFrame = function(){
  3.   if(hitLast>=4){
  4.     gotoAndPlay(2);
  5.     delete this.onEnterFrame;
  6.   }
  7. }


And on frame 200 of the movieclip symbol add in
Code: [ Select ]
_root.hitLast++
Although I never recommend using _root to target things, I don't really feel like getting into targetting and variable scopes and such, so as long as you aren't loadMovie-ing this into another movie, you should be fine.

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.