我會使用單獨的加載程序的每個圖像,你想加載。下面是一個如何實現它的快速示例:
*編輯:它正在關閉軟件包部分,請原諒我不理解stackoverflow的代碼解析器。 *
`package
{ import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.net.URLRequest;
public class LoaderTest extends Sprite
{
//two loaders
private var _firstLoader:Loader = new Loader();
private var _secondLoader:Loader = new Loader();
//just assuming you already have the buttons you want setup, use these as theoretical buttons
private var _buttonOne:Sprite;
private var _buttonTwo:Sprite;
public function LoaderTest()
{
_firstLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
_secondLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
_firstLoader.load(new URLRequest("path/to/image.jpg"));
_secondLoader.load(new URLRequest("path/to/image.jpg"));
_buttonOne.addEventListener(MouseEvent.CLICK, showImage);
_buttonTwo.addEventListener(MouseEvent.CLICK, showImage);
}
private function imageLoaded(e:Event):void
{
//do something if you want
}
private function showImage(e:MouseEvent):void
{
switch(e.target)
{
case _buttonOne :
if (!contains(_firstLoader))
{
if (contains(_secondLoader))
removeChild(_secondLoader);
addChild(_firstLoader);
}
break;
case _buttonTwo :
if (!contains(_secondLoader))
{
if (contains(_firstLoader))
removeChild(_firstLoader);
addChild(_secondLoader);
}
break;
}
}
}
} `
可以顯示一些代碼? – bhups 2010-07-18 18:47:54