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".
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.
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.
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
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?
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:
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?
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 🙂
Copy link to clipboard
Copied
*throws hands up*
this.myMovieClip.theName_of_MY_CustomProperty = "bananaramadingdong";
That's it.
Copy link to clipboard
Copied
Bingo, thank you!