Skip to main content
Participant
May 30, 2020
Question

Custom Symbol Type Class

  • May 30, 2020
  • 1 reply
  • 728 views

I'm looking for a way to designate a custom javascript class for instantiated symbols.  I have developed/coopted a hacky way to associate programattically instantiated symbols with a specific javascript class, but I can't seem to force Animate to use my classes for timeline-instantiated instances. 

Does anyone know if this is possible?  Or at least a way to catch when a certain type of symbol has been instantiated on the timeline?

    This topic has been closed for replies.

    1 reply

    Legend
    May 30, 2020

    What exactly do you mean by designating a class for symbols? All symbols already derive from the CreateJS MovieClip class. JavaScript doesn't support multiple inheritance, so if you want to bolt some custom methods to all symbols, just add them to MovieClip.

     

    http://phrogz.net/js/classes/ExtendingJavaScriptObjectsAndClasses.html

     

    Participant
    May 30, 2020

    I've successfully extended  the class, the problem is I can't get Animate to use my custom class when it creates symbol instances in the timeline.   

    Right now, I have linked a class to a symbol in Animate, gotten a reference to the linked class from the library, extended the linked class, and then replaced createJs's reference to the linked class in the library object.  When I instntiate a copy of the symbol in js, it uses my custom class straight from the Library object, but when it's instantiated by the timeline, it's still using the original linked class.  

    Legend
    May 30, 2020

    Yikes. Why aren't you just adding to the base class, like this?

    createjs.MovieClip.prototype.test = function() {
    	alert(this);
    }

    Works perfectly for runtime and timeline instantiated symbols.

     

    What do you even need this for anyway? What functionality are you adding that must exist as a method of every single symbol in the project? A procedural library that accepts symbol references as arguments would probably do the job just as well.