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

Use the data-* attribute to embed custom data

Community Beginner ,
Nov 12, 2020 Nov 12, 2020

Is there a way I can assign extra/other data params to movieclips like we can do with html a tags - https://www.w3schools.com/tags/att_global_data.asp

I have.a bunch of movie clip icons where I need to assign each a group of values I can access in an onclick function. For now I just need to do a javasctip alert and show the values when an icon is clicked. For example, I'd like to add something like data-name="Thunderbird", data-level="Expert", data-link="https://mylink.com".

462
Translate
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 13, 2020 Nov 13, 2020

In Canvas documents movieclips are just JavaScript objects, so you can add whatever properties or methods you want to them.

Translate
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 13, 2020 Nov 13, 2020

Can you point me in direction on code examples, I'm not sure wha to search for to find this. Thanks.

Translate
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 13, 2020 Nov 13, 2020

Found this, but how would I attached the info to a movieclip?

https://www.dyn-web.com/tutorials/object-literal/properties.php

Translate
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 13, 2020 Nov 13, 2020

You're assigning click functions so you already know how to address movieclips on the stage. You've read the linked article so you know exactly how properties are added. What more is there to teach you?

Translate
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 13, 2020 Nov 13, 2020

I can't get a values to log to the console, getting undefined. Here I add the pieces I need to the mc named icon_1:

var icon_1 = {
	title: 'Jupiter',
	level: 'Expert',
	vid: 'https://www.youtube.com/watch?v=xyz'
}

 Then I have a click function to show a value in the console (the other 2 funtions work):

function overF(e) {
	e.currentTarget.gotoAndPlay("over");
	this.cursor = "pointer";
}
function outF(e) {
	e.currentTarget.gotoAndPlay("out");
	this.cursor = "default";
}
function clickF(e) {
	console.log(e.currentTarget.level);
}

Tried replacing e.currentTarget.level with:

  • e.currentTarget.name.level
  • this.e.currentTarget.level
  • this.level
Translate
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 13, 2020 Nov 13, 2020

Hold up. You have a movieclip named icon_1, and you're also creating a local variable named icon_1?

Translate
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 13, 2020 Nov 13, 2020

I guess thats what it's doing, but I need to assign those 3 values to the icon_1 mc then read them. Thanks for looking at this. I'm trying here 🙂 

Translate
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 13, 2020 Nov 13, 2020

*throws hands up*

 

this.myMovieClip.theName_of_MY_CustomProperty = "bananaramadingdong";

 

That's it.

 

Translate
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 13, 2020 Nov 13, 2020
LATEST

Bingo, thank you!

Translate
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