我可以使用xml文件中的以下代码加载外部png文件,
function $LoadLogo($Logo:URLRequest,$Target:MovieClip)
{
var $Loader:Loader = new Loader();
$Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, $LoadedFunction);
$Loader.load($Logo);
function $LoadedFunction(e:Event)
{
$Target.Logo.Image.addChild($Loader);
}
}
$LoadLogo("Logos/logo.png", ScaneLogo)
但是当我在xml中更改png的url时,我想从“ScaneLogo.Logo.Image”中删除这个加载的png,并在运行时将新的png加载到“ScaneLogo.Logo.Image”。
电影层次结构如下
root - > ScaneLogo(MovieClip) - >徽标(MovieClip) - >图片(MovieClip)
现在非常感谢。
答案 0 :(得分:0)
//create this variable outside the scope of the function
var $Loader:Loader;
function $LoadLogo($Logo:URLRequest,$Target:MovieClip):void {
//remove all existing children/images from the movieclip
while ($Target.Logo.Image.numChildren > 0) {
$Target.Logo.Image.removeChildAt($Target.Logo.Image.numChildren-1);
}
//null the existing image loader to prevent a memory leak
$Loader = null;
$Loader = new Loader();
$Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, $LoadedFunction);
$Loader.load($Logo);
function $LoadedFunction(e:Event):void {
$Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, $LoadedFunction);
$Target.Logo.Image.addChild($Loader);
}
}
$LoadLogo("Logos/logo.png", ScaneLogo)