views:

973

answers:

2

I have five movie clips in my library. I want to load each to the stage with a fade in and fade out. I thought I could just call them into an array, but I can't find how to reference them. I have other clips in the library too so I can't just grab them all.

Anyone know how to do this? AS3, please.

TIA

A: 

The effect is often called an image rotator. If your clips aren't being loaded dynamic, why not just dump them to the timeline and animate them fading by hand. That would take all of 5 minutes to accomplish.

Soviut
Because he's not using the timeline?
a paid nerd
It sounded like he had a self contained scene with clips in the library already. The quickest solution is to forego the coding completely and just lay out the animation manually. Otherwise, if it needs to be dynamic for reasons he didn't mention, then code is necessary.
Soviut
Mainly because I want to learn. But they will be loaded dynamically as well.
A: 

Right click on your MovieClip item in the library. Select the "Export for ActionScript". This will then fill in the class field. Selected Ok twice. Lets say your class was called 'mcSquare'

var mySquare:mcSquare = new mcSquare();
addChild(mySquare);

To then fade them in simply set the alpha of the mySquare to 0 (directly before or after addChild) and then tween the alpha of the clip to 1.

EDIT:

Label the movieclips in your library mc0, mc1 and so on. In this example up to mc6.

const MAX_ITEMS:uint = 7; //if you have seven movielips
var container:Array = new Array();

for (var i:int = 0;i < MAX_ITEMS;i++)
{
  var className:Class = getDefinitionByName("mc"+i) as Class;
  var newMovieClip:MovieClip= new className();
  container.push(newMovieClip)

}

for (var k:int = 0; k < MAX_ITEMS;k++)
{
   var myClip:MovieClip = container[k] as MovieClip;
   myClip.alpha = 0;
   stage.addChild(myClip);
   //apply tweening to myClip

}
Allan
How would this work in an array? I want to be able to find how many of the clips there are, then cycle through each of them. I was thinking that I can then do the animation just once.
Not sure I follow? You can create an array and the push the mySquare variable into it. Then loop through the array and apply a function to do the tweening?
Allan
See my edit. Maybe this is what you mean.
Allan
Allan,That looks like it. Bad news is, I left the file at work so won't be until tomorrow. But it sure looks like what I was thinking.
Allan, thanks. Worked fine. Appreciate the help!Cheers!