简体   繁体   中英

Adobe Animate CC, HTML5 Canvas - capture instance names as dynamic text?

Forgive me, I'm not a proper JS programmer and still getting my head around a lot of concepts.

Suppose one had a group of similar, 2-frame/2-state rollover movie clips nested inside a containing clip, which has the instance name "Map". Each clip uses a 4 digit ID number preceded by an "s" as an instance name – eg, "s6566".

Suppose one then wanted to capture those respective instance names to define a variable, such that one small script could allow each of these movie clips to display their ID on rollover/active state (in this case "6566"), across multiple files.

Ultimately I have thousands of these little clips spread across several dozen documents, and it seems it should be fairly simple to grab each symbol's instance name/ID, strip off the "s" from the beginning (there because instance names can't begin with a numeral), and apply said ID as dynamic text to it's respective symbol's rollover/active frame.

Is there a method of achieving this goal? I wish I had some example code to include here, but I'm not quite sure how to begin, other than to lay out the problem thusly. Haven't yet been able to find any info on capturing instance names, and I'm not sure whether it's possible. Thanks.

Children of MovieClips are stored as references using their instance name. You can see the format in the exported library JS file. Note that Animate will convert some instance names to remove unsupported characters or duplicates.

Here is some untested pseudo-code to get you started.

// You can iterate a MovieClip and get the names
for (var name in someMovieClip) {
    // Ignore anything not starting with an s
    if (name.substr(0,1) != "s") { continue; }

    // remove the s
    var newName = name.substr(1);

    // The child can be accessed using bracket-access with its name
    var child = someMovieClip[name];

    // The child should have text instances if it is set up how you described
    // Set the text to the newName
    child.textInstance.text = newName
}

Don't forget to update the stage after you make changes. If you already have Ticker set up to do that, it should update immediately.

I hope that helps. If you have follow-up questions, let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM