Help with bitMapdata and moviecliploader

I used Ordinathorreur’s example (from http://www.kirupa.com/forum/showthread.php?t=201509&highlight=load+jpg) on how to load an external jpg and then use the bitMapdata class to copy it to avoid jaggies when i rotate the pic…but:

I dont like having an onEnterFrame running the whole time just to load a pic every once in a while so i tried using a loadClip (which i want anyway) and then use the onLoadComplete or the onLoadProgress to test if the pic is loaded.

Nothing works… probably just som stupid mistake but i would be grateful if someone would take a look at my code:


import flash.display.BitmapData;
loaded = 0;
getThisPic = 0;


var polClip:MovieClipLoader = new MovieClipLoader();
var polLoadListener:Object = new Object();
polClip.addListener(polLoadListener);

but.onRelease = function() {
    loadPic();
};


loadPic = function () {
    i = 0;
    while (getThisPic == loaded) {
        i++;
        getThisPic = Math.floor(Math.random()*5+1);
    }
    loaded = getThisPic;
    polClip.unloadClip(target_mc);
    polClip.loadClip("randomgallery/"+getThisPic+".jpg", "holder");
};

//**************method1

polLoadListener.onLoadComplete = function(target_mc) {
    myBitmapData = new flash.display.BitmapData(holder._width, holder._height, true, 0x00FFFFFF);
    myBitmapData.draw(_root.holder);
    _root.holder2.attachBitmap(myBitmapData, 1, "auto", true);
};

//**************method2

/*
polLoadListener.onLoadProgress = function(target_mc, lBytes, tBytes) {
    pText.text = Math.round((lBytes/tBytes)*100);
    if (lBytes == tBytes) {
        myBitmapData = new flash.display.BitmapData(holder._width, holder._height, true, 0x00FFFFFF);
        myBitmapData.draw(_root.holder);
        _root.holder2.attachBitmap(myBitmapData, 1, "auto", true);
    }
};
*/
//**************method3
/*
_root.onEnterFrame = function() {
    if (_root.holder.getBytesLoaded() == _root.holder.getBytesTotal()) {
        myBitmapData = new flash.display.BitmapData(holder._width, holder._height, true, 0x00FFFFFF);
        myBitmapData.draw(_root.holder);
        _root.holder2.attachBitmap(myBitmapData, 1, "auto", true);
    }
};
*/

… as i said: the only one of the three methods above that works is the onEnterFrame.

It looks like your method 1 is almost right. Just replace onLoadComplete with onLoadInit. onLoadComplete is rather misleading as to when the event callback actually takes place. I think that was why I used onEnterFrame to illustrate it in my last example, I wasn’t aware of it then.
The rest of that code block seems alright. Post again if it doesn’t work.

:}

Oh yeah, and put the var keyword in front of the bitmap variable when you declare it, that should help out on the memory management side of things.

i.e var myBitmapData = new flash bla bla bleep bleep… toot toot

Thank you thank you thank you!!!

it works.

I spent hours on it and it was driving me absolutely nuts.

The site is still about a week away from being finished but i’m looking forward to getting some feedback from the community.

Btw: Can you explain, or refer me me to somewhere, that explains what you mean about the var statement and memory manegement? … there are a couple of concepts that completely escapes me in flash.

GD

Well that variable then only exists in the scope of that function. Once the function code has finished running the Flash garbage collector comes in and cleans up after you, removing that variable from your computer memory. :slight_smile: It’s nice like that.

This concept is especially important when using the BitMapData object as you would otherwise keep a copy of that bitmap in memory, and well that can quickly get out of hand.

ahh… i see - once again: Thank you

GD

No problem man :slight_smile:

Hope everything works out for you…