Comparison of JavaFX Script to actionscript

Color
JavaFX Scriptactionscript
Rectangle { fill: Color.BLACK }
Rectangle { fill: Color.rgb(255,204,0) }
Rectangle { fill: Color.web("#ff0066") }
Rectangle { stroke: Color.BLACK }
Shape
JavaFX Scriptactionscript
Line { startX: 30 startY: 20 endX: 30 endY: 20 }
Rectangle { x: 10 y: 20 width: 30 height: 30 fill: Color.WHITE stroke: Color.BLACK }
Path { stoke: Color.BLACK MoveTo LineTo LineTo LineTo }
Variables and Datatypes
JavaFX Scriptactionscript
var x = 70;//initialize x = 30;
var x = 70.0;
var a = [5,6,7]; //initialize a[0] = 12; //reassign
var a = [5,6,7]; //initialize insert 12 into a; //append
Loops and Conditionals
JavaFX Scriptactionscript
while(true) { // do stuff }
for(i in [0..10]) { // do stuff }
//loop over a sequence for(i in a) { // do stuff }
if(c == 1) { // do stuff }
if(c != 1) { // do stuff }
if(c < 1) { // do stuff }
if(c < 1 and c > 1) { // do stuff }
if(c != 1) { // do stuff } else if (d != 1) { // do other stuff } else { // do last stuff }
Structure
JavaFX Scriptactionscript
//comment
/* comment */
public function doStuff(x:Number):Void { // do stuff } doStuff(12);
public function doStuff(x:Number):Number { // do stuff // return num; } x = doStuff(12);
Input
JavaFX Scriptactionscript
Rectangle { onMousePressed: function(e:MouseEvent) { x = e.getX(); } onMouseDragged: function(e:MouseEvent) { x = e.getX(); } }
Rectangle { onKeyPressed: function(e:KeyEvent) { var key = e.getKeyChar(); } }
Animation
JavaFX Scriptactionscript
var rect = Rectangle { } var anim = Timeline { keyFrames: [ at(0s) { rect.x => 100}, at(1s) { rect.x => 200}, ] repeatCount: Timeline.INDEFINITE toggle: true };
Binding and Triggers
JavaFX Scriptactionscript
var foo = 0.0; var bar = bind foo; foo = 2.2; // bar is updated
// create a class with a trigger public class Foo { public attribute bar:Number = 0.0 on replace { System.out.println("bar was changed to {bar}"); } }
Packages and Import Statements
JavaFX Scriptactionscript
package org.myname.myapp;
import java.lang.System;
Class Definition
JavaFX Scriptactionscript
//declare a class public class Foo extends CustomNode { // attributes and functions go here }
//declare an attribute public class Foo extends CustomNode { public attribute bar:Number = 1.0; }
//declare a function public class Foo extends CustomNode { public function baz(a:Number, b:String):Number { return a*2; } }
Audio and Video
JavaFX Scriptactionscript
// Create a video player import javafx.scene.media.*; MediaView { mediaPlayer: MediaPlayer { media: Media { source: "file://myvideo.mov" } } }
// Create an audio player import javafx.scene.media.*; MediaView { mediaPlayer: MediaPlayer { media: Media { source: "file://myvideo.mp3" } } }