1

I've started to try out the ScalaFX API few days ago. To learn the usage of this API I'm looking at the examples on GitHub. For testing out the features of the TimeLine class I used this example: ScalaFXAnimation.

The code to define a TimeLine object is looking like this in the example:

val timeline = new Timeline {
  cycleCount = Timeline.Indefinite
  autoReverse = true
  keyFrames = Seq(
    at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
    at (4 s) {rect1.x -> 300d},
    at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
    at (4 s) {rect2.y -> 300d},
    at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
  )
}

If I try to do this in my own project I recieve some compile errors like:

Error:(58, 5) not found: value cycleCount

The values autoReverse, keyFrames and s are also not found. I did not set up the project and its structure by myself but cloned an "Hello world"-project from GitHub: scalafx-hello-world. This project and compiled properly.

Could it be a bug in ScalaFX? Do you have any ideas how to solve this problem?

EDIT2: Complete Code

package hello

import scalafx.animation.{Timeline, Interpolator}
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle
import scalafx.Includes._
import scala.language.postfixOps

object ScalaFXHelloWorld extends JFXApp {

  val rect1 = new Rectangle {
    width = 100
    height = 200
    fill = Color.Red
  }

  val rect2 = new Rectangle {
    width = 200
    height = 120
    fill = Color.Green
  }

  val timeline = Timeline {
    cycleCount = Timeline.Indefinite
    autoReverse = true
    keyFrames = Seq(
      at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
      at (4 s) {rect1.x -> 300d},
      at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
      at (4 s) {rect2.y -> 300d},
      at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
    )
  }

  timeline.play()
  stage = new PrimaryStage {
    scene = new Scene {
      content = List(rect1, rect2)
    }
  }
}
  • The code above is taken straight from an example that works correctly. Your problem, possibly, is with includes that are bringing JavaFX rather than ScalaFX classes. Can you post a complete piece of code that you have problem with, with "includeds"? – Jarek Feb 20 '15 at 18:57
  • No I used the same imports as the example. Made an edit to the post with the imports – Mario P. Waxenegger Feb 20 '15 at 19:32
  • Code you posted so far, looks fine. Though those are just fragments, the issue is somewhere else. Can you post complete example that can be used to reproduce your compilation error? – Jarek Feb 20 '15 at 20:22
  • Made another edit with the complete source code - I think it's quite the same as in the example – Mario P. Waxenegger Feb 20 '15 at 20:38

1 Answers1

3

In the latest version you are missing new in front of Timeline. It should be:

val timeline = new Timeline { 
   ... 
}
Jarek
  • 1,513
  • 9
  • 16
  • Thank's a lot. Now it works, but IntelliJ still tells me that it `cannot resolve symbol s`. But thats maybe a problem with my IDE... – Mario P. Waxenegger Feb 20 '15 at 21:10
  • 1
    @MarioP.Waxenegger I know it's a little late, but I had the same problem. The way to fix it is to change `1 s` to use a float or double such as `1.0 s`. – J Atkin Nov 26 '15 at 14:10