Solved

Add MovieClips to stage

Posted on 2010-09-09
4
342 Views
Last Modified: 2012-05-10
I'm trying to display a bunch of movie clips on the screen.  I know I could just place them there, define their property name, and work with them in the code, but I have to place 100 of them, so it would be much easier to do it in the code. I'm working in AS3 with the Flash IDE.
0
Comment
Question by:walker6o9
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Jakob_E
ID: 33643669
Hi,

It looks like you need a loop - like:

// Array referencing your movie clips
var clips:Array=[mc001, mc002, mc003, ...., mc100]

// Loop adding the clips
for(var i:int=0; i<clips.length; ++i){
  addChild(clip[i])
}



To give you a better answer pleaser try to elaborate on what you want done,
how you create your movie clips (script/stage/library or loaded) etc.
 

Best,
Jakob E
0
 
LVL 1

Author Comment

by:walker6o9
ID: 33643676
I have a movie clip called balloon.  To place them on the stage, I just dragged them onto the stage from the library, then called then balloon1_mc, balloon2_mc, etc.  I'd like to place them all on the stage without doing that so that I can reference them in my code later on, and move them around, etc.
0
 
LVL 1

Author Comment

by:walker6o9
ID: 33648658
So basically, this is how I'm adding one movie clip to the stage.

var balloon_mc1 = new balloon();
this.addChild(balloon_mc1);

How do I do this for 100 of these movie clips, without typing
var balloon_mc1 = new balloon();
this.addChild(balloon_mc1);

var balloon_mc2 = new balloon();
this.addChild(balloon_mc2);

var balloon_mc3 = new balloon();
this.addChild(balloon_mc3);

etc, etc
0
 
LVL 9

Accepted Solution

by:
Jakob_E earned 500 total points
ID: 33650233
In this case try (Iv'e renamed balloon to Balloon):


// Array holding the balloons
var baloons:Array=[];

// Add 100 balloon clips to the stage and the balloons array
for(var i:int=0; i<100; ++i){
  var mc:Balloon=new Balloon();
  mc.x=Math.random()*stage.stageWidth;  // Random x position
  mc.y=Math.random()*stage.stageHeight; // Random y position
  addChild(mc);
  baloons.push(mc);
}
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now