terça-feira, março 30, 2010

smoothImageLoader

Esse scrip é um para quem problema em carregar imagens externas e depois redimensionar, os créditos não são meus achei ele no site frontend-multimedia estou aqui apenas propagando um bom código.

Aqui a função:

_global.smoothImageLoad = function(imgURL, targetMovie) {
var i = 0;
do {
i++;
} while (eval("_root.smoothImageLoadTemp"+i) != undefined);
tmc = _root.createEmptyMovieClip("smoothImageLoadTemp"+i, _root.getNextHighestDepth());
tmc.createEmptyMovieClip("ti",tmc.getNextHighestDepth());
tmc.tm = targetMovie;
with (tmc) {
tmcl = new MovieClipLoader();
tmcl.onLoadComplete = function() {
ti.onEnterFrame = function() {
pixelData = new flash.display.BitmapData(ti._width, ti._height);
pixelData.draw(ti);
tm.attachBitmap(pixelData,1,true,true);
tm.smoothImageLoadComplete();
removeMovieClip(ti._parent);
};
};
tmcl.loadClip(imgURL,tmc.ti);
}
};

Aqui você chama a imagem e o movie clip alvo.

smoothImageLoad("image.jpg", mytargetmc)

Um trace básico pra ver se deu carto.

mytargetmc.smoothImageLoadComplete = function() {
trace("opa deu certo!")
}

Marcadores: , , ,