ActionScript 3 AS3中图像URL的自定义光标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3中图像URL的自定义光标相关的知识,希望对你有一定的参考价值。

package  {
	
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.ui.Mouse;
	
	
	public class CustomCursor extends Sprite {
		
		private var request:URLRequest;
		private var cursorLoader:Loader;
		
		/*	When you create a custom cursor, pass in the URL of the cursor you want to use	*/
		public function CustomCursor(url:String='crosshair_image.png') {
			setCursor(url);
		}
		
		public function setCursor(url:String):void
		{
			/*	Load our image from the url path	*/
			request = new URLRequest(url);
			cursorLoader = new Loader();
			cursorLoader.load(request);
			/*	Listen for when the content of the loader is finished loading	*/
			cursorLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, cursorLoaded);
		}
		
		private function cursorLoaded(event:Event):void
		{
			/*	The width and height of the new cursor	*/
			var w:Number = event.target.width;
			var h:Number = event.target.height;
			
			/*	Center the image on the mouse	*/
			cursorLoader.x = -w/2;
			cursorLoader.y = -h/2;
			
			/*	Hide the default cursor	*/
			Mouse.hide();
			
			/*	Add the cursor graphic to the stage	*/
			addChild(cursorLoader);
			
			/*	startDrag keeps the object the same x,y as the mouse cursor	*/
			this.startDrag(true);
		}
	}
}

以上是关于ActionScript 3 AS3中图像URL的自定义光标的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3从URL加载外部SWF

ActionScript 3 AS3从远程URL加载外部SWF

ActionScript 3 Flash Preloader as3代码就像苹果风格。

ActionScript 3 AS3从URL或文件名获取文件扩展名

Rails 3 中图像路径的完整 url

ActionScript 3 AS3 |的ArrayCollection