Why do I need the IF when using two movies

Below is a direct copy from the processing reference guide. I’m sure it will work, but I’m pretty new here, so I would like to understand why I need the if statement in the movieEvent.
Basically why can’t this be just m.read() instead of the construct with the if.

trying to learn something :wink:

import processing.video.*;

Movie myMovie, yourMovie;

void setup() {
  size(200, 200);
  myMovie = new Movie(this, "totoro.mov");
  yourMovie = new Movie(this, "catbus.mov");
  myMovie.play();
  yourMovie.play();
}

void draw() {
  image(myMovie, 0, 0);
  image(yourMovie, 100, 0);  
}

void movieEvent(Movie m) {
  if (m == myMovie) {
    myMovie.read();
  } else if (m == yourMovie) {
    yourMovie.read();
  }
}


In this case two movies are handled

When you only have one movie, you don’t need the if

The if has the purpose that we distinguish between the two movies since they share the same function here

but if the Movie m is a parameter to the movieEvent(), doesn’t it point to the movie that triggered the event?
It feels odd to me that I can do
if (m == myMovie) { myMovie.read(); }
but
if (m == myMovie) { m.read(); }
would be bad. and if it isn’t bad why can’t I just do m.read()

Good point

Definitely worth a try

it works just fine without the IF, but I’m trying to understand why the reference manual makes an explicit point of it to do it with the IF statement. It’s probably more a java question than a processing one, but i would like to understand it.

Hi @illus,

Guess it is only for demonstration purpose, if you need to know which movie triggers the event.
You can simply use m.read() if you are not interested on the latter…
As the several movie objects triggering the same event (method name) you’ll get the correct frame for each movie…

Cheers
— mnse

1 Like