在调用addNodeFilled()
使用外部位图文件作为填充的函数之前,我必须使用 Loader 类将位图文件加载到 Flash Player 中,并等待加载器完成加载并触发Event.COMPLETE
并执行相应的事件处理程序onComplete()
。为了确保这一点,我有一个 while 循环来等待加载完成,但是在运行程序时,程序 esp 循环无限地进行,这意味着在闪存中,事件处理程序与主序列同步执行,直到结束addNodeFilled()
才能执行addNodeFilled()
. 通常代码addNodeFilled()
放在onComplete
事件处理程序中,但我无法做到这一点,需要随时调用,addNodeFilled()
但检查加载完成,我该怎么做?
var stitch:BitmapData = new BitmapData(16, 16);
var loaderStatus:String = "busy";
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("file:///E:/Projects/FlashDevelop/Terracotta/assets/Stripe.jpg"));
addNodeFilled(100, 100);
//function definitions===============================================
function onComplete(event:Event):void
{
stitch = event.target.content.bitmapData;
loaderStatus = "loaded";
} //onComplete
function addNodeFilled(posx:Number, posy:Number):void
{
while(loaderStatus != "loaded")
{
trace("waiting for loader");
}
var grid:Rectangle = new Rectangle(5, 5, 5, 5);
var nodeDecal:Sprite = new Sprite();
nodeDecal.graphics.beginBitmapFill(stitch, null, true, true);
nodeDecal.graphics.drawRoundRectComplex(posx, posy, 80, 16, 0, 0, 4, 4);
nodeDecal.scale9Grid = grid;
addChild(nodeDecal);
} //addNodeFilled