Skip to main content
xu zhang
Inspiring
June 28, 2017
Answered

How can i get the id of the canvas?

  • June 28, 2017
  • 3 replies
  • 7659 views

HI,thans you help first!

for example:

lib.properties = {

  id: '054D1722FC18B043A207F8FDCA4D6A20',

  width: 1024,

  height: 768,

  fps: 12,

  color: "#FFFFFF",

  opacity: 1.00,

  manifest: [

  {src:"images/_1.jpg?1498542790116", id:"_1"}

  ],

  preloads: []

};

we can get the lib like this:

var comp=AdobeAn.getComposition("054D1722FC18B043A207F8FDCA4D6A20");

var lib=comp.getLibrary();

but ,if i don't know the id,so i can't get the id like above.

so how can it do it ?

thanks !

This topic has been closed for replies.
Correct answer ClayUUID

I think so. Many people will have read both, but it would be good to see if Adobe Animate users have ideas. I'll move it.


Huh, who would have thought Adobe would decide to complicate the Animate CC API by inflicting Edge's "compositions" concept on it.

Well anyway, this isn't that hard. Just do:

var lib = AdobeAn.getComposition(Object.keys(AdobeAn.compositions)[0]).getLibrary();

Err, okay that is a little dense. Broken down into a multi-liner, the above would be:

var key = Object.keys(AdobeAn.compositions)[0];

var comp = AdobeAn.getComposition(key);

var lib = comp.getLibrary();

Object.keys is a method supported by newer browsers that returns an array of all the keys (property names) on an object. Assuming an Animate project only has a single "composition", the code above just grabs the first element of the keys array.

Wait... so this means Animate 2017 no longer populates the lib global, which means they just broke every single project that uses bla = new lib.linkageName to instantiate objects from the library. My god.

I'd be submitting an angrily-worded bug report to Adobe regarding this. At the very least there should be a less obtuse method for pages to access their own library. This is looking like Adobe actively trying to discourage developers from using the library object.

3 replies

eeroleppanen
Participant
July 6, 2017

Hi,

this is indeed Animate CC question, as xu zhang suggested, the structure of library and the way to call it have changed since June 2017 release.

br, eero

Legend
June 28, 2017

This is an Edge Animate question, not Animate CC.

Colin Holgate
Inspiring
June 28, 2017

I did wonder why someone was doing things the hard way! My answer is probably still good though. Should we move this to Edge Animate, if there is still a forum for it?

Legend
June 28, 2017

It's not that it's the hard way, it's more the completely inapplicable way. There is no such function as getComposition() in Animate CC. That's an Edge function.

Colin Holgate
Inspiring
June 28, 2017

It looks like lib.properties is being set to an object, which would make the id be lib.properties.id.

xu zhang
xu zhangAuthor
Inspiring
June 29, 2017

I'm sorry, may I didn't fully describe the problem. The new version of the animation CC export HTML JS files changed, I don't want to go to edit export documents. How to get the id number in the lib.

new animation cc add bootstrap callback support,and export the JS files like this:

(function (cjs, an) {

var p; // shortcut to reference prototypes

var lib={};var ss={};var img={};

lib.ssMetadata = [];

// symbols:

// stage content:

// library properties:

lib.properties = {

  id: '054D1722FC18B043A207F8FDCA4D6A20',

  width: 1024,

  height: 768,

  fps: 12,

  color: "#FFFFFF",

  opacity: 1.00,

  manifest: [

  {src:"images/_1.jpg?1498542790116", id:"_1"}

  ],

  preloads: []

};

// bootstrap callback support:

(lib.Stage = function(canvas) {

  createjs.Stage.call(this, canvas);

}).prototype = p = new createjs.Stage();

p.setAutoPlay = function(autoPlay) {

  this.tickEnabled = autoPlay;

}

p.play = function() { this.tickEnabled = true; this.getChildAt(0).gotoAndPlay(this.getTimelinePosition()) }

p.stop = function(ms) { if(ms) this.seek(ms); this.tickEnabled = false; }

p.seek = function(ms) { this.tickEnabled = true; this.getChildAt(0).gotoAndStop(lib.properties.fps * ms / 1000); }

p.getDuration = function() { return this.getChildAt(0).totalFrames / lib.properties.fps * 1000; }

p.getTimelinePosition = function() { return this.getChildAt(0).currentFrame / lib.properties.fps * 1000; }

an.bootcompsLoaded = an.bootcompsLoaded || [];

if(!an.bootstrapListeners) {

  an.bootstrapListeners=[];

}

an.bootstrapCallback=function(fnCallback) {

  an.bootstrapListeners.push(fnCallback);

  if(an.bootcompsLoaded.length > 0) {

  for(var i=0; i<an.bootcompsLoaded.length; ++i) {

  fnCallback(an.bootcompsLoaded);

  }

  }

};

an.compositions = an.compositions || {};

an.compositions['054D1722FC18B043A207F8FDCA4D6A20'] = {

  getStage: function() { return exportRoot.getStage(); },

  getLibrary: function() { return lib; },

  getSpriteSheet: function() { return ss; },

  getImages: function() { return img; }

};

an.compositionLoaded = function(id) {

  an.bootcompsLoaded.push(id);

  for(var j=0; j<an.bootstrapListeners.length; j++) {

  an.bootstrapListeners(id);

  }

}

an.getComposition = function(id) {

  return an.compositions[id];

}

})(createjs = createjs||{}, AdobeAn = AdobeAn||{});

var createjs, AdobeAn;

old animation cc export the JS files like this:

(function (lib, img, cjs, ss, an) {

//content;}

})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{}, AdobeAn = AdobeAn||{});

var lib, images, createjs, ss, AdobeAn;

so,old version we can get lib.properties,but new version lib is not defined.

Colin Holgate
Inspiring
July 6, 2017

I tried what I suggested earlier, this:

alert(lib.properties.id);

shows the id of the lib. Does that not work for you?