Riddlah
Riddlah

Reputation: 302

adding Bitmaps to various frames in movieClip in as3

I have a movieClip and I want attach to this movieClip bitmaps. I want attach each bitmap to different frame of movieClip. I have tried something like this, but it is not working. It is for memory game I am creating.

for(var i : int = 0; i < cardList.length; i++){
    var helpVar : int = cardList[i].pictureOfCard;
    cardList[i].gotoAndStop(cardList[i].pictureOfCard+2);
    var bitmap : Bitmap = new Bitmap(bitMapArray[helpVar].bitmapData.clone());
    cardList[i].addChild(bitmap);
    cardList[i].gotoAndStop(1);
}

Upvotes: 2

Views: 1054

Answers (3)

Riddlah
Riddlah

Reputation: 302

After some time I discover that what I was trying to achieve is probably not possible in as3. The way I solved my problem is that everytime i gotoAndStop to frame I need have there bitmap I addChild(bitmap) and everytime I gotoAndStop other frame where there should not be bitmap I removeChild(bitmap) from movieClip. (So it is very similar aproach to makeing bitmap visible and invisible)

Upvotes: 1

devsnd
devsnd

Reputation: 7722

You could simply load all Bitmaps and only show the one, that should be visible right now. e.g.

function ShowFrame(nr:int):void{
   for(i:int = 0; i<bitMapArray.length; i++){
      bitMapArray[i].visible = false;
   }
   bitMapArray[nr].visible = true
}

My AS3 skills are rusty, so this might need some syntax correction, but it works in theory.

Upvotes: 1

sanchez
sanchez

Reputation: 4530

var i :int = 0;
processNext();

function processNext():void
{
   cardList[i].addEventListener(Event.FRAME_CONSTRUCTED, onFrameConstructed );
   cardList[i].gotoAndStop(cardList[i].pictureOfCard+2);
}


function onFrameConstructed( e:Event ):void
{
    cardList[i].removeEventListener(Event.FRAME_CONSTRUCTED, onFrameConstructed );
    var helpVar : int = cardList[i].pictureOfCard;        
    var bitmap : Bitmap = new Bitmap(bitMapArray[helpVar].bitmapData.clone());
    cardList[i].addChild(bitmap); 

    if( i < cardList.length - 1 )
    {
       i++;
       processNext();
    {
    else
       trace("All done");

}

Upvotes: 1

Related Questions