开发者

How to loop through different movie clips in AS3?

I have five movie clips in m开发者_如何学编程y 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


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

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜