views:

84

answers:

0

I have a bitmap rpeviously loaded and added as child to a movielip mc then i want to load another image later and remove thatchild and replace with the new one.. for some reason my code doesnt work..i dont know what im doing wrong

i add a listener to a thumbnail called openBigImage so basically the new file path and filename should replace the previous image

imgLoader is a movieclip that contains varius image previously delared as img0, img1 etc..

theThumbs contain the images filenames as string

my question is: should img.addChildAt(bitmapContent,0); works as a swapper function? i can remove the img child but i cant replace it...

function openBigImage(e) 
{
    var e = e.target;
    var i = e.parent.name1;
    var z = e.parent.name2;
    var tu = theThumbs[i][z];   
    var img =  imgLoader.getChildByName("img" + i);
    var newimg:Loader = new Loader();
    var fileRequest:URLRequest = new URLRequest(tu);    
    newimg.load(fileRequest);
    newimg.name = i;
    newimg.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleted2);
    img.removeChildAt(0);
}
function onLoadCompleted2(e:Event):void {
    var bitmapContent:Bitmap = Bitmap( e.target.content );
    bitmapContent.smoothing = true;
    var i = e.target.loader.name;
    var img =  imgLoader.getChildByName("img" + i); 
    trace("img" + i)
    img.addChildAt(bitmapContent,0);
}