⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadimg.as

📁 基于AS3的图片展示 图片缩放不模糊 导入外部XML数据
💻 AS
字号:
package thisclass{
	import flash.display.Bitmap
	import flash.display.BitmapData
	import flash.display.Sprite;
	import flash.display.MovieClip
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent
	import flash.events.ProgressEvent;
	
	import fl.transitions.*;
	import fl.transitions.Tween;
	import fl.transitions.TweenEvent;
	import fl.transitions.easing.*;
	
	import thisclass.createMC;
	public class loadimg extends MovieClip {
		private var myTween:Tween
		private var loading:createMC = new createMC(300,50);
		private var click_mc:createMC 
		private var loader:Loader = new Loader();
		private var bitmap:Bitmap
		public function loadimg(str:String) {
			var urlrequest:URLRequest = new URLRequest(str);
			
			loader.load(urlrequest);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,load_comp);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,load_pro);
			addChild(loader);
			addChild(loading);
		}
		private function load_comp(event:Event):void {
			myTween = new Tween(event.currentTarget.loader, "alpha", Strong.easeIn, 0, 1, 0.5, true);
			myTween.addEventListener(TweenEvent.MOTION_FINISH,tween_alpha_finish)
		    event.currentTarget.loader.parent.x=(stage.stageWidth-event.currentTarget.loader.parent.width)/2
			event.currentTarget.loader.parent.y=(stage.stageHeight-event.currentTarget.loader.parent.height)/2
			//trace("导入完成");
		}
		private function load_pro(event:ProgressEvent):void {
			loading.string="loading..."+String(Math.round(event.bytesLoaded/event.bytesTotal*100))+"%";
			if (event.bytesLoaded/event.bytesTotal == 1) {
				removeChild(loading)
				loading = null
			}
		}
		private function img_mousedown(event:MouseEvent):void {
			var tempmc:createMC = new createMC(bitmap.width,bitmap.height);
			tempmc.alpha = 0.1
			tempmc.name = "tempmc";
			tempmc.x = bitmap.x;
			tempmc.y = bitmap.y;
			tempmc.startDrag();
			tempmc.addEventListener(MouseEvent.MOUSE_UP,tempmc_mouseup);
			addChild(tempmc);
		}
		private function tempmc_mouseup(event:MouseEvent):void {
			img_click(event.currentTarget.x,event.currentTarget.y);
			removeChild(getChildByName("tempmc"));
		}
		private function img_click(newx:int,newy:int):void {
			myTween = new Tween(bitmap, "x", Strong.easeIn, bitmap.x, newx, 0.3, true);
			myTween = new Tween(bitmap, "y", Strong.easeIn, bitmap.y, newy, 0.3, true);
			myTween.addEventListener(TweenEvent.MOTION_FINISH,tween_finish)
		}
		private function tween_finish(event:TweenEvent):void{
			click_mc.x=bitmap.x
			click_mc.y=bitmap.y
			click_mc.width=bitmap.width
			click_mc.height=bitmap.height
		}
		private function tween_alpha_finish(event:TweenEvent):void{
			bitmap = Bitmap(loader.content)
			bitmap.smoothing = true
			addChild(bitmap)
			
			click_mc = new createMC(bitmap.width,bitmap.height);
			click_mc.alpha = 0
			click_mc.addEventListener(MouseEvent.MOUSE_DOWN,img_mousedown)
			addChild(click_mc)
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -