• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

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?
TOPICS
Code , Error

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

LEGEND , Dec 02, 2019 Dec 02, 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

...

Votes

Translate

Translate
Community Expert , Dec 10, 2019 Dec 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

Votes

Translate

Translate
Community Beginner ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2019 Nov 29, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2019 Nov 29, 2019

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 29, 2019 Nov 29, 2019

Copy link to clipboard

Copied

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.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2019 Nov 29, 2019

Copy link to clipboard

Copied

Animate CC has always had the name property for Canvas documents. In 2018 and earlier it's assigned null. In 2019 it's assigned the instance name. In 2020 it's back to null. I'm going to give Adobe the benefit of the doubt and assume this regression was accidental instead of intentional.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2019 Dec 02, 2019

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2019 Dec 08, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2019 Dec 11, 2019

Copy link to clipboard

Copied

LATEST

Hi Clay,

 

That is true, I had not noticed how the loop would quickly terminate for display objects that have a name, nicely written. However, for display objects that DON'T have an instance name (which in my case is the vast majority) the entire loop would need to be completed before it could be assertained that no name existed.

 

I guess this is kinda pointless now because the issue has been fixed, but... anyway. Thank you for going to the effort to write out the code for me, that is above and beyond.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2019 Dec 11, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines