Skip to main content
Known Participant
February 4, 2021
Question

Link a library symbol to a js Class

  • February 4, 2021
  • 2 replies
  • 353 views

Hi,

i've a symbol score in the library with a link ("Score").

I have the choice, for instanciate it, between :

 

var score1=new lib.Score();

 

then, i have the good graphics but i haven't any code associate to it.

 

var score1=new lib.Score();

 

then, i have all the functions and code associate to it but any graphics.

 

Is it possible to have a graphics link to a class, like with the as3 Class ? And if not, how to apporach of that ?

 

Thanks for your replies.

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 4, 2021

    Hi.

     

    I really didn't get what you want.

     

    Do you mind providing a code example and/or an use case?

     

     

    Regards,

    JC

    defiraidAuthor
    Known Participant
    February 4, 2021

    this works but it's really not nice :

    class Score {
        constructor(cible, x, y) {
            var key = Object.keys(AdobeAn.compositions)[0];
            var comp = AdobeAn.getComposition(key);
            var lib = comp.getLibrary();
            this.MC = new lib.Score();
            this.MC.x = x;
            this.MC.y = y;
            cible.addChild(this.MC);
        }
    }

    and i have to copy the 3 lines about AdobeAn in each class of this sort.

    And that's composition instead of inheritance (i prefer the second for this type of class).

    Maybe by transforming the library symbol into a component but i didn't find anything about that.

    Thanks for your reply.

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 5, 2021

    Hi.

     

    Sorry for the delay.

     

    So for me to understand: do you have a game and you want to add a score at runtime?

     

    What exactly are you not being able to do?

    defiraidAuthor
    Known Participant
    February 4, 2021

    In fact, i try to extend the createJS MovieClip class in an extern class Score.