FLASH AS3 载入外部图片作为背景平铺,MC剧中的方法。
import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.display.Loader; import flash.net.URLRequest; import flash.display.Sprite; import flash.display.BitmapData; import flash.display.Bitmap; stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE, resizeHandler); stage.dispatchEvent(new Event(Event.RESIZE)); var _rootBackGround:Sprite; var backImage:MovieClip = new MovieClip(); this.addChild(backImage); var loader:Loader = new Loader(); loader.load(new URLRequest("bg.jpg")); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoadResult); function resizeHandler(e:Event):void { banner.y = stage.stageHeight / 2 - banner.height / 2; banner.x = stage.stageWidth / 2 - banner.width / 2; trace(banner.x + banner.y); } function showLoadResult(event:Event):void { var _bitmap:Bitmap = Bitmap(loader.content); var matrix:Matrix = new Matrix(1,0,0,1,this.stage.stageWidth / 2,this.stage.stageHeight / 2); var sampleSprite:Sprite = new Sprite(); sampleSprite.graphics.beginBitmapFill(_bitmap.bitmapData, matrix , true , true); sampleSprite.graphics.drawRect(0, 0, 20000, 20000); sampleSprite.graphics.endFill(); backImage.addChild(sampleSprite); setChildIndex(backImage,0); }