求教育,Flash高手请进!
首先新建一个影片剪辑Image 实例名:tool_1_001
设置其类为:LoadPic
下面是LoadPic的代码:
[code=Java]ackage {
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.events.Event;
public class LoadPic extends Sprite {
private var show_loader:Loader;
private var path_urlrequest:URLRequest;
private varpath_url:String = " ";
public function get Path_url():String
{
return path_url;
}
public function set Path_url(_value:String):void
{
if(path_url!=_value)
{
path_url =_value;
LoadPic_1();
}
}
public function LoadPic_1(){
path_urlrequest=new URLRequest(path_url);
show_loader=new Loader;
show_loader.load(path_urlrequest);
show_loader.contentLoaderInfo.addEventListener(Event.COMPLETE ,LoadComplete);
}
// public function LoadPic_2(){
// show_loader.unload();
// }
private function LoadComplete(_evt:Event):void {
var _bmp:Bitmap=_evt.target.loader.content as Bitmap;
// trace(_bmp.width,_bmp.height );//测试出宽和高
this.width=_bmp.width/2;
this.height=_bmp.height/2;
addChild(_bmp);
}
}
}
[/code]
想利用这个控件对图片进行动态加载!
问题:
现在发现在第一次加载图片之后,
再次加载图片就会发生重叠现象!求解决方案!
[解决办法]
这东西不能叫控件吧。
这个类继承了sprit,那你再次载入的时候把这个sprit干掉就好了啊。用removeChild。
也可以直接改改这个类:
package { import flash.display.Sprite; import flash.display.Loader; import flash.net.URLRequest; import flash.display.Bitmap; import flash.events.Event; public class hh extends Sprite { private var show_loader:Loader = new Loader(); private var path_urlrequest:URLRequest; private var path_url:String = " "; public function get Path_url():String { return path_url; } public function set Path_url(_value:String):void { if (path_url != _value) { path_url = _value; LoadPic_1(); } } public function LoadPic_1() { path_urlrequest = new URLRequest(path_url); show_loader.unload(); show_loader.load(path_urlrequest); show_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,LoadComplete); } } private function LoadComplete(_evt:Event):void { var _bmp:Bitmap = _evt.target.loader.content as Bitmap; this.width = _bmp.width / 2; this.height = _bmp.height / 2; addChild(_bmp); } }}