as3 绘制Sprite背景色

1.可以用来更改Flash背景风格

        private function imgLoader(imagePath:String):void
        {
            skinsLoader = new Loader();
            skinsLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imgLoaderComplete);
            skinsLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,imgIOErrorHandler);
            var urlRequest:URLRequest = new URLRequest();
            urlRequest.url = "resource/"+imagePath;
            skinsLoader.load(urlRequest);

        }
        
        private function imgLoaderComplete(event:Event):void
        {
            var bitmap:Bitmap = event.target.content as Bitmap;
            bitmap.width = stage.stageWidth, bitmap.height = stage.stageHeight;
            var bitmapData:BitmapData=bitmap.bitmapData;
            this.graphics.beginFill(0x000000); 
            this.graphics.drawRect(0,0,this.width,this.height);
            this.graphics.beginBitmapFill(bitmapData);
            this.graphics.drawRect(this.x,this.y,this.width,this.height);
            this.graphics.endFill();
           
            skinsLoader.contentLoaderInfo.removeEventListener (Event.COMPLETE , imgLoaderComplete);
            skinsLoader.contentLoaderInfo.removeEventListener (IOErrorEvent.IO_ERROR , imgIOErrorHandler);
            skinsLoader = null;
        }
posted @ 2012-06-27 11:31  William Jiang  阅读(1980)  评论(0编辑  收藏  举报