Skip to main content
Participant
April 8, 2022
Question

How do you create a multidimensional array in Adobe Animate?

  • April 8, 2022
  • 4 replies
  • 580 views

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. 

 

This topic has been closed for replies.

4 replies

kglad
Community Expert
Community Expert
April 10, 2022

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ésar17023019'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;

 

 

Legend
April 10, 2022

Using objects would be overkill for something this simple.

kglad
Community Expert
Community Expert
April 10, 2022

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?

Legend
April 10, 2022

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

JoãoCésar17023019
Community Expert
Community Expert
April 8, 2022

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

Participant
April 8, 2022

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