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

How do you create a multidimensional array in Adobe Animate?

Community Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

I'm trying to create an array of jokes with the question (setup) and punchline (answer). This is something i could easily do in ActionScript, but I'm clueless where to start in Adobe Animate, Javascript etc. 

 

For example:  I can create an array easily enough: 

var Jokes = ["How does the sea greet the pirate?"];
var Jokes2 = ["It Waves!"];

But how do I combine the two into one array as if it were on object?

Title: Pirate

Setup: How does the sea greet the pirate?

Punchline: It Waves!

Would I create an array called Pirate and make the punchline and setup elements? 

Var Pirate = ["How does the sea greet the pirate?","It Waves"];

Then create a joke array to hold the Pirate array?

var Jokes = [Pirate];

I've tried the above but can't retrieve the elements. 

 

TOPICS
Code , How to , Other

Views

302

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

As a follow up... How do I make the array accessable throughout the entire timeline if my array is created in frame 0?

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 Expert ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

Hi.

 

Maybe is this what you want?

 

// questions is a property of the current timeline
// so it can be accessed in other frames
this.questions =
[
	{ title:"Pirates", setup:"How...?", punchline: "It Waves!" },
	{ title:"Pirates 1", setup:"How...1?", punchline: "It Waves 1!" },
	{ title:"Pirates 2", setup:"How...2?", punchline: "It Waves 2!" },
];

 

 

Please let us know.

 

Regards,

JC

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 ,
Apr 10, 2022 Apr 10, 2022

Copy link to clipboard

Copied

Array syntax in ActionScript and JavaScript is exactly the same. Your example code works perfectly in Animate.

 

The global variable exportRoot is automatically created in canvas documents and points to the root timeline.

 

Alternatively, "this" in any timeline will always reference that timeline (except for in event handlers).

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 Expert ,
Apr 10, 2022 Apr 10, 2022

Copy link to clipboard

Copied

as both the above stated, use "this" to reference a timeline (outside a function body).  then to reference, use

 

var Pirate0 = [setup0,answer0];

var Pirate1 = [setup1,answer1];

this.jokes = [Pirate0,Pirate1];

 

// setup0 = this.jokes[0][0];

// answer0 = this.jokes[0][1];

 

but @JoãoCésar's suggestion to use an object is probably preferable (or even an array of objects):

 

this.jokes = [{setup:"setup 0",answer:"answer 0"},{setup:"setup 1",answer:"answer 1"}, etc];

 

then for the 2nd joke:

 

var setup=this.jokes[1].setup;

var answer = this.jokes[1].answer;

 

 

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 ,
Apr 10, 2022 Apr 10, 2022

Copy link to clipboard

Copied

Using objects would be overkill for something this simple.

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 Expert ,
Apr 10, 2022 Apr 10, 2022

Copy link to clipboard

Copied

i have no idea what you mean, in this situation, by "overkill". 

 

my first two guesses were performance and ease-of-use, but performance is a negligible factor (unless there are a lot more than a few million jokes) and while objects are more verbose, they are easier for humans to use.

 

so, something else?

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 ,
Apr 11, 2022 Apr 11, 2022

Copy link to clipboard

Copied

By overkill I mean it would be overkill. This is a data set with only two items per sub-array, and they even have a natural order (setup, answer). Storing them as named objects would add nothing but verbosity.

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 Expert ,
Apr 11, 2022 Apr 11, 2022

Copy link to clipboard

Copied

LATEST

agree with the verbosity, but we disagree that it's a drawback.

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