title: JavaFX stop Timeline
body: <p>I use FXML. I've created a button to stop/restart a live chart. For the animation I've used Timeline. I'would like to control it from the guiController (from an other class), but it is not working. How can I stop a Timeline from an other class?</p>
  
  <p>Thank you!</p>
  
  <p>FXML:</p>
  
  <pre><code>            &lt;Button id="button" layoutX="691.0" layoutY="305.0" mnemonicParsing="false" onAction="#btn_startmes" prefHeight="34.0" prefWidth="115.0" text="%start" /&gt;
  </code></pre>
  
  <p>guiController:</p>
  
  <pre><code>@FXML      
  private void btn_stopmes(ActionEvent event) {
    MotionCFp Stopping = new MotionCFp();
  Stopping.animation.stop();
  }  
  </code></pre>
  
  <p>MotionCFp.java:</p>
  
  <pre><code>    @Override
      public void start(final Stage stage) throws Exception {
         else{
          ResourceBundle motionCFp = ResourceBundle.getBundle("motionc.fp.Bundle", new Locale("en", "EN"));
          AnchorPane root = (AnchorPane) FXMLLoader.load(MotionCFp.class.getResource("gui.fxml"), motionCFp);
          final guiController gui = new guiController();
          Scene scene = new Scene(root);
          stage.setTitle(motionCFp.getString("title"));
          stage.setResizable(false);
          stage.setScene(scene);        
          root.getChildren().add(gui.createChart());
                  animation = new Timeline();
                  animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler&lt;ActionEvent&gt;() {
              @Override public void handle(ActionEvent actionEvent) {
                  // 6 minutes data per frame
                  for(int count=0; count &lt; 6; count++) {
                      gui.nextTime();
                      gui.plotTime();
                      animation.pause();
                      animation.play();
                  }
              }
          }));
          animation.setCycleCount(Animation.INDEFINITE);
          stage.show();
          animation.play();
         } 
  
     }
  </code></pre>