Vishwas
Vishwas

Reputation: 1541

Accessing pieces of bitmaps inside a movieclip

I have a movieclip with 10 bitmaps in it. I wanna access each of them.

myMovieClip is the movieclip containing those 10 bitmaps. I wanna access those bitmaps one by one. All 10 bitmaps are imported separately. I tried this :

for ( var i =0 ; i< myMovieClip.numChildren ; i++)
{


    trace ( myMovieClip.getChildAt(i) ); 

}

Problem is numChildren comes "1" only, as if it doesnot consider those 10 pieces of bitmap. Any other way, to access those bitmaps ?

thanks V.

Upvotes: 1

Views: 721

Answers (1)

Travis
Travis

Reputation: 461

what do you mean by pieces of bitmaps?? Do you mean 10 different bitmap objects are children of the movieClip??

In addition, your code does have a syntax error.

var newMc:MovieClip = MovieClip();

should be:

var newMc:MovieClip = new MovieClip();

second off all, in your loop, numChildren will be always changing since you are taking the reference of a child from the myMoiveClip and moving it to the newMc object. there are two way to fix this.

either set a local variable to the value of myMovieClip.numChildren and use that value in your loop example:

var numOfChildren:int = myMovieClip.numChildren;
for(var i:int = 0; i < numOfChildren; i++){
     var newMc:MovieClip = new MovieClip();    
     newMc.addChild(myMovieClip.getChildAt(i)); 
} 

this will move the bitmaps out of myMovieClip and into newMc, if you want to keep them there you can create a new bitmap inside the loop and then add the new bitmap to the newMc. example:

for(var i:int = 0; i < myMovieClip.numChildren; i++){
     var newMc:MovieClip = new MovieClip(); 
     var b:Bitmap = new Bitmap(Bitmap(myMovieClip.getChildAt(i)).bitmapData);   
     newMc.addChild(b);
}

Upvotes: 2

Related Questions