A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: BitmapData

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    10

    BitmapData

    I have this code.

    Code:
    import flash.display.BitmapData
    
    var seq:Array = new Array();
    var MAX_IMAGES_COUNT = 10;
    
    for (var i=0; i < MAX_IMAGES_COUNT; i++)
    {	
    	this.createEmptyMovieClip("temp_mc",this.getNextHighestDepth());
    	temp_mc.loadMovie("img/img"+i+".png");	
    	seq.push(BitmapData = new BitmapData(320,240,true,0x00FFFFFF));
    	seq[i].draw(temp_mc);
    	temp_mc.removeMovieClip();	
    }
    
    this.attachBitmap(seq[0],this.getNextHighestDepth());
    I got empty white screen. Why I can't see first image of my image sequnce? What I do wrong?

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    If this is for AS3, removeMovie doesn't exist anymore, and there are things called Bitmap's now, not just BitmapData.

  3. #3
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    You will see a white screen because the external movies you are loading into your dynamically generated movieclips have not yet fully loaded movieclip.loadMovie() is asynchronous meaning it doesnt occur instantly, or to be blunt, the action doesnt occur before the next line of code executes.

    Therefore you need to use the built-in events that the movieclip class provides to check that the external movies have fully loaded and then blit the movieclip into the bitmap. I prefer to use the MovieClipLoader class to load and monitor external movies, as you will see below, because the MovieClip.onLoad method is buggy.

    Code:
    import flash.display.BitmapData
    
    images=new Array();
    MAX_IMAGES_COUNT = 10;
    currentImage=0
    
    loadNextImage()
    
    
    function loadNextImage()
    {
    	++currentImage
    	if(holder_mc != undefined)
    	{
    		holder_mc.removeMovieClip()
    	}
    	this.createEmptyMovieClip("holder_mc",this.getNextHighestDepth());
    	var ml=new MovieClipLoader()
    	ml.addListener(this)
    	ml.loadClip("img/img"+currentImage+".png",holder_mc);
    }
    
    function onLoadInit(target:MovieClip)
    {
        var bmp:BitmapData = new BitmapData(320,240,true,0x00FFFFFF);
        bmp.draw(target);
        images.push(bmp);
        if(images.length == MAX_IMAGES_COUNT)
        {
    		allImagesLoaded()
        }
    	else
    	{
    		loadNextImage()
    	}
    }
    
    function allImagesLoaded()
    {
    	holder_mc.removeMovieClip()
    	this.attachBitmap(images[0],this.getNextHighestDepth());
    }
    The code above, loads one image at a time, waits until the image is loaded and then blits it into a bitmap which is stored in the correct order inside the images array, it will stop when it reaches MAX_IMAGES_COUNT.

  4. #4
    Junior Member
    Join Date
    Sep 2006
    Posts
    10
    Okey thanks! I'll try that when I get back to my own computer and let you know if I got it working.

  5. #5
    Junior Member
    Join Date
    Sep 2006
    Posts
    10
    I forget to ask this earlier but why this thread is moved to under AS3 category?

  6. #6
    Junior Member
    Join Date
    Sep 2006
    Posts
    10
    Thanks FlashGuru! It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center