Another way of getting objects and tween behavior in javascript

Is there another way to get objects from scene and its tween behavior in javascript?

I am creating an extension with a behavior: TweenGroup. Basically it would allow one to easily apply the same tween in a group of objects. I created the code and a sample project, and submitted the extension. Currently, it complains about this:

disallowedProperty: 'getObjects',
disallowedProperty: 'TweenRuntimeBehavior

Is there another way to get the objects in the scene and its tween behavior, and use them?

I am currently doing it like this:

// get the object containing the behavior
const currObj = eventsFunctionContext.getObjects("Object")[0];

// when doing for other objects, I do it like this
const obj = runtimeScene.getObjects(elementName)[0];

// get attached tween behavior
let tween = currObj.getBehavior("Tween");

// creating a new tween (all the params are created correctly, since the demo project works)
tween.addObjectPositionXTween(tweenName, x, easingFn, duration, false);

I’m not 100% sure there is another way to get the tween behavior via JS. I do know that you can only call objects in extensions that have been added as parameters in the extension itself, I vaguely remember that being true for JS as well.

But just to check, why are you making a full JS extension instead of just putting the objects into an object group then applying the tween to that object group in a “for each” type event? That’d apply the tween to all of them, and would only be a single event or two.

Because I would like to do more than just apply the exactly same tween.

For instance, if I am making a sliding menu, I want all elements to slide from a direction, but keeping the same relative position between them. So, instead of doing a position y tween, I need a position y tween where I add a value to its current y position. Also, I added a delay param, so that it is possible to apply the tweens with a fixed delay between them, causing a domino effect.

The recommended way to get objects is through the “objects” parameter on the header of the JS event, as this preserves object picking, unlike getting the objects with runtimeScene#getObjects.

Although the way you are getting the tween behavior should work most of the time, it is recommended to use eventsFunctionContext#getBehaviorName instead of hard-coding "Tween", just in case the name of the behavior instance is not the name of the behavior itself, or if there are multiple instances of the behavior on a single object, which are extremely rare but technically possible and supported cases.
The system was not complaining about your usage of the behavior instance itself, though. It complains that your code seems to be using the constructor of the behavior (i.a. new gdjs.TweenRuntimeObject()). It must be coming from some other JS code in your extension.

By using the objects parameter on the header of the JS event, can I get all the objects created in the scene?

In my extension I first register an element as part of the group, then later I iterate through the objects in the scene with that name, and get all the instances. Only then I access its tween behavior. I am not using eventsFunctionContext#getBehaviorName there since it will return the name TweenGroup instead of Tween. Basically, what I do is:

for (let i = 0; i < elementsNames.length; i++) {
    const elementName = elementsNames[i].getAsString();

    // get objects by its name
    const objs = runtimeScene.getObjects(elementName);

    for (let j = 0; j < objs.length; j++) {
        const obj = objs[j];

        // get attached tween behavior
        tween = obj.getBehavior("Tween");

But I don’t call this constructor directly in any part of my code. Maybe this is called inside the addTween functions like addObjectPositionYTween, and that’s why it is complaining?