javascript classes in separate files?

Apr 21, 2006 at 5:42pm

javascript classes in separate files?

hello,

apologies in advance if this is a dumb question, javascript is not my
first language and i’m still getting used to it’s funky prototype-
based object-oriented-ness.

I’m trying to break up a huge file of code into smaller files, each
with a single javascript class in them. Each file compiles fine on
it’s own (after loading them into the [js] object), but I can’t seem
to get inheritance to work – when I create a test patch that
instantiates a class defined in an external file, I get “ClassName is
not defined” in the max window. I tried putting each file in the
same directory as the patch I’m testing them with, and also in the
C74/jsextensions directory.

I tried creating a test file containing only “var j3d = new
Jitter3dUtilsInterface();” and it didn’t give any errors. But, when
I created a js file called test.js with the line “post(“testing”)”
and put that in the jsextensions directory, I didn’t see any out put
to the max window. I feel like I’m missing something simple here,
but I’ve been through the javascriptinmax manual and came up empty.
Please, someone save my sanity… i’ve written 2,000 lines of code in
4 days and my eyes are all blurry…

thanks,
evan

#25574
Apr 21, 2006 at 6:01pm

In case anyone’s interested, I put the code here:

http://misssynthesis.com/jsbuttons.html

It’s for making jsui GUI buttons, one is a simple Button class that
responds to UI events, the other is an extension of that, that
displays an icon (loaded from an image file with jsui’s Image
object). It’s still rough, but possibly useful. Any feedback
appreciated…

#75424
Apr 21, 2006 at 7:18pm

Which version of Max are you using ? post is global since 4.5.5, I
think. This could explain why… or not…

Best,
ej

#75425
Apr 22, 2006 at 12:26am

max 4.5.7, jitter 1.5.2

not sure what you mean, if post() was global, wouldn’t i see output
in the max window?
my whole goal is to be able to have a class defined in a file, say it
was named “test.js”, located in the jsextensions folder, and
contained something like:

function Test()
{
this.test = function() { post(“testing”); }
}

then I could create another js file, called “testing_test.js”:

var tester = new Test();
tester.test();

And I should see “testing” printed to the max window.
Right?
I hope this makes sense, please let me know if I’m not being clear.

thanks,
-Evan

#75426
Apr 22, 2006 at 2:36pm

On 22 avr. 06, at 02:26, evan.raskob wrote:

> max 4.5.7, jitter 1.5.2
>
> not sure what you mean, if post() was global, wouldn’t i see output
> in the max window?

Before 4.5.5 it wasn’t possible to call the post() method inside the
jsextensions folder.

> And I should see “testing” printed to the max window.
> Right?

It doesn’t help much more, but it works here : max 4.5.7 on mac
10.4.6 and windows.

ej

#75427

You must be logged in to reply to this topic.