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

Use the data-* attribute to embed custom data

Community Beginner ,
Nov 12, 2020 Nov 12, 2020

Copy link to clipboard

Copied

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

Views

274

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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 🙂 

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

Copy link to clipboard

Copied

*throws hands up*

 

this.myMovieClip.theName_of_MY_CustomProperty = "bananaramadingdong";

 

That's it.

 

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

Copy link to clipboard

Copied

LATEST

Bingo, thank you!

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