Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

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

Débutant dans la communauté ,
Nov 28, 2019 Nov 28, 2019

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?
SUJETS
Code , Erreur
2.5K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 2 bonnes réponses

LÉGENDE , 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

...
Traduire
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

Traduire
Débutant dans la communauté ,
Nov 28, 2019 Nov 28, 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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 29, 2019 Nov 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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
LÉGENDE ,
Nov 29, 2019 Nov 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.

 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Nov 29, 2019 Nov 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.  

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
LÉGENDE ,
Nov 29, 2019 Nov 29, 2019

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
LÉGENDE ,
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 in your initialization section so it only runs once. Then just call as myinstance.getName();

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Dec 08, 2019 Dec 08, 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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
LÉGENDE ,
Dec 09, 2019 Dec 09, 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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Dec 11, 2019 Dec 11, 2019
LA PLUS RÉCENTE

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Dec 11, 2019 Dec 11, 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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines