as3 绘制Sprite背景色

原文链接:http://www.cnblogs.com/WilliamJiang/archive/2012/06/27/2565521.html

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;
        }

转载于:https://www.cnblogs.com/WilliamJiang/archive/2012/06/27/2565521.html

上一篇:iOS自制火柴人动画CC_Sprite程序员自己做动画


下一篇:COCOS学习--精灵(5)