-
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?
-
Senior Member
If this is for AS3, removeMovie doesn't exist anymore, and there are things called Bitmap's now, not just BitmapData.
-
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.
-
Okey thanks! I'll try that when I get back to my own computer and let you know if I got it working.
-
I forget to ask this earlier but why this thread is moved to under AS3 category?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|