Monday, February 9, 2015

How to create a JavascriptObject object?

So I have an existing "class" in javascript that takes an element and then draws into it using a canvas.  In javascript, you create it like this:

    var timeline = new Timeline(document.getElementById("canvas"));

I'd like to wrap this in GWT using a JavascriptObject but I'm not sure how to create it.  Here's what I'm trying:

    public class Timeline extends JavaScriptObject {
      protected Timeline() {}
      public static native Timeline create(Element canvas) /*-{ r
        return new Timeline(canvas); 
      }-*/;
    }

And then try to create a timeline using this:

    Timeline timeline = Timeline.create(DOM.getElementById("canvas"));

Given what I've read I'd expect this to work but when running in super devmode I get something like: Uncaught ReferenceError: r is not defined.

I haven't yet tested this outside of super devmode because I can't figure out how to (I've been using GWT for many years but have never used super devmode).  I think I'm doing everything right and have isolated it to the code examples given.

Thanks for the help!

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment