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

Put movie clips in an array and then place them using JavaScript

Community Beginner ,
Jan 10, 2021 Jan 10, 2021

Copy link to clipboard

Copied

I used to do AS3 and am new to JavaScript.  I want to put my movie clips into an array (so later I can randomize their order) and choose some of them to display.  In AS3 I’d put them in an “Assets” layer so they aren’t on the screen, instantiate them, put them in an array, and then place them with “addChild.”  How do I do this in Animate using JavaScript?  All I have so far is:

var answer1Array = ["up1", "down1", "left1", "right1"];

TOPICS
Code , How to

Views

218

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 ,
Jan 11, 2021 Jan 11, 2021

Copy link to clipboard

Copied

Hi.

 

In HTML5 Canvas documents you need to assign a linkage name to the symbol in the Library you want to add at runtime.

image.png

 

Then you can write your code like this:

var root = this;
var i;

root.platforms = []; // the array is a property of the main timeline so you can reference it in another frames

for (i = 0; i < 7; i++)
{
	var platform = new lib.Platform();
	
	platform.x = Math.random() * lib.properties.width;
	platform.y = Math.random() * lib.properties.height;
	root.addChild(platform);
	root.platforms[i] = platform;
}

 

I hope it helps.

 

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
Community Beginner ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

LATEST

Thank you for your reply!  I'm not sure this answers my question, though. 

 

In my noob reading of this code it looks like it adds instance names to a symbol in my library and then puts 7 of them in an array - is this right?

 

In my Canvas document, I have given the symbols instance names and put them in an array.  What I need to know is how do I then use this array to place the symbols on the stage?  

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