Posted by: vikingo Jan 14 2007, 10:31 PM
Hi all
I will like to know how to load multiple external images
I'm using code below (from http://www.petitpub.com) but I can't understand how Listener works.
CODE
box = new Box(80,80,80,'tri');
// Create a MovieClip to hold the externally loaded image
// Make it fully transparent ( or move it out of the stage )
var holder:MovieClip = createEmptyMovieClip( "holder", getNextHighestDepth() );
holder._alpha = 0;
// Create a MovieClipLoader and listen to it
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener( this );
// Delegate the event handling to get the correct scope ( this )
onLoadInit = Delegate.create( this, paste );
mcLoader.loadClip( "petit110110.png", holder );
// Loader handler
function paste( mc:MovieClip ) {
var bitmap:BitmapData = new BitmapData( mc._width, mc._height,true,0x00FFFFFF);
bitmap.draw( mc );
faces = box.getFaces();
faces[9].setSkin(new TextureSkin( bitmap ));
faces[8].setSkin(new TextureSkin( bitmap ));
}
I used to use this sintaxis but it won't work.
CODE
var holder:MovieClip = createEmptyMovieClip( "holder", getNextHighestDepth() );
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
Delegate.create( target_mc, paste );
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("petit110110.png", holder );
So using the Petit example it's difficult to me to load multiple images
I will like to know if anyone canl help me
Meanwhile I'm testing it...
Thanks!
Posted by: Petit Jan 15 2007, 12:04 AM
QUOTE(vikingo @ Jan 14 2007, 11:31 PM)

Hi all
I will like to know how to load multiple external images
I'm
using code below ( from
http://petitpub.com/labs/media/flash/sandy/%5dhttp://petitpub.com ) but
but I can't understand how Listener works.
Hmm.. I'm not sure what the problem is with your code.
My listener works like this:
I add 'this' as listener, which means the application itself listens for events from the MovieClipLoader.
This
event is fired when the image is loaded, so the application must have
an onLoadInit handler, which in this case is the paste() method.
Why do I use the Delegate class?
Well, if the loadInit calls paste() directly, we cannot use the faces Array.
The event handler cannot access the array - it has its own scope.
The popular solution is to create a delegation and send the the scope we want to use,
here it is 'this' because the faces Array is owned by the application itself.
You
are sending the target_mc to the Delegate.create() method, so the
paste() method may not be able to access the faces of your object.
You
can load all images you want, using this method. You can do this in a
loop, and have a separate MovieClipLoader for each image. You can
delegate the same paste() method for all. The images will queue up for
handler, as they load.
Finally in the paste() method you convert the image to a BitmapData object and add it as a skin to one of the faces.
Do experiment and good luck!
Posted by: Petit Jan 15 2007, 12:19 AM
Hmm.. strange behavior when inserting the likn to my tutorial.
It should be http://petitpub.com/labs/media/flash/sandy/
( I hope