title: Is It Possible To Import Classes into FXML <fx:script> block (JavaFX-2)
body: <p>I'm trying out JavaFX-2 and one of the features is said to be that we can create event handler functions using Javascript in our FXML file. One thing that bugged me is I can't access the System class right away. It needs to be fully referenced, like "java.lang.System". That becomes ugly when we need a simple output on the console, I mean come on, "System.out.println" is ugly enough to get something printed.
  And, even though my FXML has all the &lt;?import java.lang.*?&gt; statements, apparently it doesn't affect inside of the &lt;fx:script&gt; tags.</p>
  
  <p>Sample code: (Notice the <code>&lt;?language javascript?&gt;</code> directive)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?language javascript?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import java.net.*?&gt;
  &lt;?import java.util.*?&gt;
  &lt;?import javafx.collections.*?&gt;
  &lt;?import javafx.geometry.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.image.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.paint.*?&gt;
  &lt;?import javafx.scene.text.*?&gt;
  
  &lt;AnchorPane fx:id="rootPane"&gt;
    &lt;fx:script&gt;
      function buttonAction(event){
        java.lang.System.out.println("finally we get to print something.");
        // System.out.println("This wouldn't work even if it wasn't a comment line, anyway");
      }
    &lt;/fx:script&gt;
    &lt;children&gt;
      &lt;Button id="close" mnemonicParsing="false" onAction="buttonAction(event)" text=""&gt;
        &lt;graphic&gt;
          &lt;ImageView pickOnBounds="true"&gt;
            &lt;image&gt;
              &lt;Image url="@../resources/close.png" preserveRatio="true" smooth="true" /&gt;
            &lt;/image&gt;
          &lt;/ImageView&gt;
        &lt;/graphic&gt;
      &lt;/Button&gt;
    &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>So my question is: Is there any way to import classes into &lt;fx:script&gt;? I remember I was doing this in Actionscript3.0 really easy: <code>import flash.events.MouseEvent</code> ...</p>