On May 10, 11:46 pm, Steven Stark <
sstark.st...@stevenstark.com>
wrote:
> Hello,
>
> I have followed this thread and created my own custom Greensock JS artifact:
>
>
https://groups.google.com/forum/?fromgroups=#!topic/jangaroo-users/Sq...
Cool! Thanks for the engagement!
> I have the AS3 classes, and I ( assume ) the js is copying over
> correctly... now I am modifying the project to work with the new code,
> still working my way through the errors trying to compile the project.
>
> As I work away I have had a few questions in the back of my head.
>
> First off, this project was made using the AS3 version of greensock, full
> of loaders and easing references.
>
> In the JS version there are no loaders and eases use strings, not class
> references.
Well, then to be compatible with the Greensock JS implementation, you
would have to change your AS client code. The other option is to use
the original Greensock AS API and build an adapter to the JS
implementation, which of course creates a bit overhead, but simplifies
porting AS code and keeping a single code base if you want to do Flash
and HTML5 a lot.
> Also, I am not entirely clear about how to go about 'stubbing' the JS
> functions in my new AS3 Classes. For example, TweenLite.
>
> in as3 it's com.greensock.TweenLite
>
> in js it's just TweenLite
>
> I want my project to use the JS version, but see as
> com.greensock.TweenLite, so I made that as3 class that looks like:
>
> package com.greensock {
>
> public native function get TweenLite():TweenLite;
>
> }
>
> This is taken from the soundManager2 example, however I am not familiar
> with the native scope and am not clear what's actually going on here.
>
> Now what about easing?
>
> I did the same for com.greensock.easing.Linear, but really I would want
> this to return a string because there is no class associated with this in
> JS.
>
> thanks for any insight on this,
>
> -Steven
The native scope just allows to define a function/method without
specifying its implementation. As the implementation is already there
(in JS), this is exactly what we want to do in the AS API.
Additionally, in Jangaroo, there is an annotation [Native] which tells
the compiler to not generate any code from this AS source file.
Now it is essential whether TweenLite is a class (in JavaScript: a
constructor function) or just a global object ("singleton").
Your code won't work, because you use "TweenLite" as a global object
*and* as its type...
If TweenLite is a class, you'd write
package com.greensock {
[Native]
public class TweenLite {
// put TweenLite's fields and methods here, using the "native"
keyword!
}
}
If it is a global object or function (that is not used with "new", but
simply called), you can denote it as an AS global object or function
inside a package:
package com.greensock {
[Native]
public const TweenLite:Object;
}
If you want to give such a global object a more specific type, you'd
have to declare that in a separate AS source file. It can be a purely
made up interface, since it is just there to provide typed access to
the fields and methods of the global JS object. As a best practice, I
use the name of the global object prefixed with "I" for such an
interface:
package com.greensock {
[Native]
public const TweenLite:ITweenLite;
}
and in com/greensock/ITweenLite.as:
package com.greensock {
public interface ITweenLite {
// put fields (as function get/set) and methods here!
}
}
Now the last thing you need is to create an alias from
com.greensock.TweenLite to (top-level) TweenLite. Jangaroo 3 will
provide support for such aliases through a parameter of the [Native]
annotation, but for Jangaroo 1 or 2, you have to create the alias as a
JavaScript object. After greesock.js and the Jangaroo Runtime are
loaded, you can use the utility function joo.getOrCreatePackage() to
create the alias:
joo.getOrCreatePackage("com.greensock").TweenLite = TweenLite;
Hope that helps,
-Frank-