AS2……啊……回忆(更像是噩梦)。
试试我的'好老' BitmapLoader.as...我已经使用了很多年,但从未让我失望过...它写得并不漂亮,而且里面有一些双作用域设置器...但是我不在乎。它很旧,而且它完美地完成了它的工作(总是!)。它需要在构造函数中设置一个布尔值,将平滑设置为 true 或 false
import flash.display.BitmapData;
class BitmapLoader extends Object {
private var mLoader : MovieClipLoader;
private var scope : Object;
private var _mc : MovieClip;
private var _url : String;
private var _func : Object;
private var smooth : Boolean;
public function BitmapLoader(smooth : Boolean)
{
this.smooth = smooth;
mLoader = new MovieClipLoader( );
addListener( this );
}
public function addListener(inListener : Object) : Void
{
mLoader.addListener( inListener );
scope = inListener;
}
public function removeListener(inListener : Object) : Void
{
mLoader.removeListener( inListener );
}
private function onLoadInit(inTarget : MovieClip) : Void
{
var bitmap : BitmapData = new BitmapData( inTarget._width, inTarget._height, true, 0x000000 );
bitmap.draw( inTarget );
var parent : MovieClip = inTarget._parent;
var img : MovieClip = parent.createEmptyMovieClip( "imageloader_smooth_mc", parent.getNextHighestDepth( ) );
inTarget.unloadMovie( );
inTarget.removeMovieClip( );
delete inTarget;
img.attachBitmap( bitmap, img.getNextHighestDepth( ), "never", true );
scope[_func]( img );
}
private function onLoadError(errorCode : String, httpStatus : Number) : Void
{
error( errorCode, httpStatus );
}
/**
* loadBitmap( http://www.test.nl/img.jpg, movieclip, "dothis");
*/
public function loadBitmap(url : String, mc : MovieClip, func : Object) : Void
{
_url = url;
_mc = mc;
_func = func;
var raw : MovieClip = _mc.createEmptyMovieClip( "imageloader_raw_mc", _mc.getNextHighestDepth( ) );
mLoader.loadClip( _url, raw );
}
private function error(errorCode : String, httpStatus : Number) : Void
{
var raw : MovieClip = _mc.createEmptyMovieClip( "imageloader_raw_mc", _mc.getNextHighestDepth( ) );
mLoader.loadClip( "img/notfound.jpg", raw );
};
}
你可以像这样使用这个类:
var loader : BitmapLoader = new BitmapLoader( true );
loader.addListener( this );
loader.loadBitmap( "http://test.nl/example.jpg", this, "doneLoading" );
'true' 是平滑布尔值,addListener(this) 是为了防止范围问题(AS2-bleeh),而“doneLoading”是它在完成加载时调用的函数名。
希望这对你有用。
祝你好运!