Skip to main content
Tristan Ward
Participating Frequently
November 29, 2019
Answered

MovieClip instance names not available from .name property in HTML5 canvas

  • November 29, 2019
  • 4 replies
  • 2590 views

Hi all,

 

Our company has a privately designed Javascript plugin for Animate's HTML5 canvas export which allows it to communicate with Adobe Captivate. Many of the features were heavily dependant on being able to read a symbol's instance name. In previous versions this was no issue, a symbol's instance name was recorded in the .name property. However, this no longer seems to be the case.

 

As you can see in the example file attached below, if you...

Create a document
Draw a square
Convert the square to a MovieClip
Give the MovieClip instance on stage an instance name (in this example: 'foobar')
Go into the MovieClip
Add the framescript: alert(this.name);
Publish
An alert will appear saying 'null'

In fact, looking through the code, the only place the instance name appears to be used is as a property on the object's parent. That's fine if you're trying to access a child from the parent, but if the child wants to know what its own name is it becomes incredibly inefficient to work that out.

 

I do not believe there is a work around for this. I'd like to be proven wrong. But otherwise, someone please, please, please fix this.

 

Parent: So, Timmy. I'd like you to-
Timmy: Who's Timmy?
This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

This issue has been fixed in the latest release: version 20.0.1 (build 19255).

 

Please update your software and it should work.

 

 

Regards,

JC

4 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
December 10, 2019

Hi.

 

This issue has been fixed in the latest release: version 20.0.1 (build 19255).

 

Please update your software and it should work.

 

 

Regards,

JC

Tristan Ward
Participating Frequently
December 12, 2019

A thousand thanks Adobe Animate team! That truly was speedy service!

 

You guys don't get as much credit as you deserve. This really saved my project. Thank you - Honestly.

Legend
December 2, 2019

Since the .name property wasn't populated in any Canvas documents until 2019, this is the code I've been using to get instance names:

 

createjs.DisplayObject.prototype.getName = function() {
	if (!this.name && this._cacheName === undefined) {
		var parent = this.parent;
		var keys = Object.keys(parent);
		var len = keys.length;
		while (--len) {
			if (parent[keys[len]] === this) {
				this._cacheName = keys[len];
				break;
			}
		}
	}
	return this.name || this._cacheName;
}

 

Stick somewhere in your initialization section so it only runs once. Then just call as myinstance.getName();

Tristan Ward
Participating Frequently
December 9, 2019

Thanks Clay,

 

I reckoned there would be a solution like this. Technically, it does fix the issue, but I am hesitant to use it because the use case requires this code to be called on every display object as soon as its created. The animations I'm working on are very complex and have many, many display objects being created and destroyed throughout. Therefore, I don't want to add a while loop into such frequently run code if I do not need to. If the Adobe Animate issue has not been fixed by the time we have to deliver then I may have to just bite the bullet and go with it, but I'm hoping that won't be necessary.

Legend
December 9, 2019

It's less looping than you'd think. In the Object.keys array, the movieclip's name seems to always end up as the second-to-last entry. So the code starts its search from the bottom, and completes within two iterations.

JoãoCésar17023019
Community Expert
Community Expert
November 29, 2019

Hi.

 

Yeah. This is probably a bug in the latest release. All instances on stage should have their name property set to the instance name given in the Properties Panel when the content is published.

 

Please report this issue here:

https://www.adobe.com/products/wishform.html

 

 

Regards,

JC

Colin Holgate
Inspiring
November 29, 2019

I believe that EaselJS has never had a name property for instances. It isn't something that broke, I think it never did work.

 

Tristan Ward
Participating Frequently
November 29, 2019

This is an excerpt from the Javascript file published by Animate in a previous release:

// WeightLifter
this.stickman = new lib.WeightLifter();
this.stickman.name = "stickman";
this.stickman.parent = this;
this.stickman.setTransform(188.65,536.95,0.4435,0.4435);
this.stickman.alpha = 0;
this.stickman._off = true;

Notice how the .name property was directly assigned?

 

In current Adobe Animate even though the name property is not directly assigned it does still exist with a value of null.  

Tristan Ward
Participating Frequently
November 29, 2019

Sorry, the forum doesn't appear to allow uploading of .fla files. However, I'm sure if you follow the steps listed above you can replicate the issue.