Error while creating two images

23 views
Skip to first unread message

25. Sai Surya

unread,
Sep 27, 2022, 7:20:29 AM9/27/22
to Developing Interactive Simulations in HTML5
Hi all,
       
        I am trying to create two images in a page, I followed example-sim code most of the part, however, I am getting below error.
       
        Uncaught TypeError: Illegal constructor
        at new TableNode (TableNode.ts:28:2)
        at new TableScreenView (TableScreenView.ts:32:20)
        at GravityScreen.createView (GravityScreen.ts:35:16)
        at GravityScreen.initializeView (Screen.ts:298:23)
        at Array.<anonymous> (Sim.ts:870:16)
        at Sim.ts:878:11
       
       
        GravityScreen.ts code is below
        super(
          () => new TableModel(),
          model => new TableScreenView( model ),
          options
        );
       
        TableScreenView code is below
        this.addChild( new TableNode( model.table, modelViewTransform ) );
       
        TableNode code below
        super();  // ERROR here that this is Illegal constructor
       
        The model I am passing to the constructor is TableModel only. Could you provide any hint on what I did wrong.
       
        Thanks & Regards,
        Sai Surya

samrreid

unread,
Sep 27, 2022, 7:02:50 PM9/27/22
to Developing Interactive Simulations in HTML5
After reading through https://stackoverflow.com/questions/41521812/illegal-constructor-with-ecmascript-6, I'm wondering if you are importing all of the relevant types, such as Node and Image from scenery.  Like in this example:


You may also need to add Node to that line, like:

import { Image, Node } from '../../../scenery/js/imports.js';

And you may need more or less dots based on your relative path.

Good luck and let us know if that works.

Best Regards
Sam

25. Sai Surya

unread,
Sep 29, 2022, 6:04:45 AM9/29/22
to Developing Interactive Simulations in HTML5

Hi Sam,

Thanks for the response, above import is indeed present in my screen JS file. I made it work earlier with single image.
This error starting popping after I introduced another model, and view similar to first image in same folder. Meaning my two models in model folder
and two views in view folder. Perhaps I will try to revert this and try.

My question is do we have any convention to follow to have models in separate folders like football under football > model and table under table > model etc.
for model and views? Or can I have all models in a single model folder and all view files in single view folder under main directory?

Thanks & Regards,
Sai Surya

25. Sai Surya

unread,
Sep 29, 2022, 6:11:24 AM9/29/22
to Developing Interactive Simulations in HTML5
My bad, I have added import { Image, Node } from '../../../scenery/js/imports.js'; to another file where this constructor is present.
I guess that made it work!

Many thanks Sam.

Regards,
Sai Surya

Reply all
Reply to author
Forward
0 new messages