Skip to main content

Casting/converting to Duration?

7 replies [Last post]
pmd
Offline
Joined: 2003-06-18
Points: 0

Is there any way to cast or convert a String or Number to Duration?

I would like the user to simply configure the duration in the simple way of just entering "24s" in a text box.

I was thinking it should be as simple as:
var refreshRate: String = "1s";
KeyFrame {time: bind (refreshRate as Duration)
or perhaps:
new Duration("24s");
... but appereantly not.

Any ideas?

Message was edited by: pmd
Spelling

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chobicus
Offline
Joined: 2006-08-31
Points: 0

Issue is fixed.
Compiler does not throw NullPointerException anymore, but code does not compile. It is fixed for null pointer.
I thought that code should compile in both versions.
Maybe I formulated issue badly.

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Which number does the issue have? You can reopen the issue and add a comment to make things clear.

chobicus
Offline
Joined: 2006-08-31
Points: 0

It's http://javafx-jira.kenai.com/browse/JFXC-2507
I commented the fix.
I didn't reopen because it is fixed not to throw NPE as I reported it did.
:)

Message was edited by: chobicus

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

You can use the valueOf-function to convert Number to Duration. I don't think there is a way to convert a String to Duration at present.

It's an interesting idea. How about writing a request in the issue tracking system? http://openjfx.java.sun.com/jira

The issue tracking system was moved to: http://javafx-jira.kenai.com

Message was edited by: michael_heinrichs

chobicus
Offline
Joined: 2006-08-31
Points: 0

This does not work:

at (Duration.valueOf(timeToFly)) {
x => -200 tween Interpolator.LINEAR
}

this works:
KeyFrame {
time : Duration.valueOf(timeToFly)
values : [
x => -200 tween Interpolator.LINEAR
]
},

where timeToFly is Number:
package var timeToFly = 3;

why?

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

This looks like a bug. Can you file an issue, please? Here is the new URL of the tracking system: http://javafx-jira.kenai.com

chobicus
Offline
Joined: 2006-08-31
Points: 0

Issue filed.
Thx for quick reply.