Skip to main content

Can't use arrays in Timelines?

2 replies [Last post]
zandig
Offline
Joined: 2006-10-16
Points: 0

I'm taking a look at the Timeline animation example in the FX Script documentation here:

http://openjfx.java.sun.com/current-build/doc/reference/ch10.html

But, I noticed that if I simply change the size variable in this example from:

var size = 1.0;

to:

var size = [1.0];

And, then access the size value by using "size[0]" within the Timeline block... it won't compile. Why is it that simply using an array index within the Timeline gives a compile error that prints:

"Sorry, I was trying to understand a key value literal expression but I got confused when I saw '[' which is an operator. Perhaps you are missing a 'SUCHTHAT'.
size[0] => 1.0;"

Are array indexes not allowed in Timelines?

Full app below:

import javafx.ext.swing.*;
import javafx.animation.*;
import javafx.scene.*;
import javafx.input.*;
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.text.*;
import javafx.scene.transform.*;
import javafx.scene.image.*;
import javafx.scene.geometry.*;
import javafx.scene.paint.*;
import javafx.scene.media.*;
import javafx.application.*;
import javafx.lang.*;
import java.lang.*;

Frame {
title: "Animation Demo";
width: 500
height: 400
visible: true
stage: Stage {
content: Rectangle {

x: 150
y: 150
// Declare variables
var rotation = 0.0;
var size = [1.0];
var color = Color.GREEN;

// Initialize attributes
cursor: Cursor.HAND
height: 50
width: 50
fill: bind color
transform: bind [
Transform.translate(-100,-100),
Transform.scale(size[0],size[0]),

// Transform.rotate(rotation,25,25)
]

// Create animation timeline
var myTimeline = Timeline {

toggle: true

// Key Frames
var begin = at (0s) {
size[0] => 1.0;
color => Color.GREEN;
rotation => 0.0;
}

var mid = at (0.5s) {
color => Color.PURPLE tween Interpolator.EASEBOTH;
}

var end = at (1s) {
size[0] => 3.0 tween Interpolator.LINEAR;
color => Color.RED tween Interpolator.EASEBOTH;
rotation => 360.0 tween Interpolator.EASEBOTH;
}

keyFrames: [begin,mid,end]
}

onMouseClicked: function(e) {
myTimeline.start();
}
}
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zandig
Offline
Joined: 2006-10-16
Points: 0
alexsch
Offline
Joined: 2007-07-12
Points: 0

Please, create a JIRA issue on it: http://openjfx.java.sun.com/jira/secure/CreateIssue!default.jspa