close

範例說明:

我有三個SWF檔案(有音訊的SWF檔),我想利用外部載入的方式使他們輪播!

效果如: http://mcr.tw/stu/gjun/carino/%E8%BC%89%E5%85%A5%E5%A4%96%E9%83%A8%E6%AA%94%E6%A1%88%E9%80%B2%E5%BA%A6%E4%B8%A6%E8%BC%AA%E6%92%AD%20OK%E7%89%88%20%20%20%E8%81%B2%E9%9F%B3%E4%B9%9F%E4%B8%8D%E6%9C%83%E5%AD%98%E5%9C%A8.swf

檔案下載: http://mcr.tw/stu/gjun/carino/%e8%bc%89%e5%85%a5%e5%a4%96%e9%83%a8SWF%e4%b8%94%e8%bc%aa%e6%92%ad.rar

 

語法:

var ldr:Loader = new Loader ;
var path:URLRequest = new URLRequest ;
var swfArray:Array = new Array("單人過關.swf","雙人過關.swf","製作名單.swf");
var arrayIndex:int = 0;
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, FnComplete);

path.url = swfArray[arrayIndex];
ldr.load(path);
arrayIndex++;

function FnComplete(e:Event)
{
ldr.scaleX = 0.29;
ldr.scaleY = 0.29;
stage.addChild(ldr);

addEventListener(Event.ENTER_FRAME,FnEnterFrame);
function FnEnterFrame(e:Event)
{
if (MovieClip(ldr.content).currentFrame == MovieClip(ldr.content).totalFrames)
{
ldr.unloadAndStop();//把之前load的所有unload且關掉~不過Flash Play10之後才有支援
path.url = swfArray[arrayIndex];
ldr.load(path);
arrayIndex++;

if (arrayIndex >swfArray.length-1)
{
arrayIndex = 0;
}
removeEventListener(Event.ENTER_FRAME,FnEnterFrame);
}
}
}

 

心得:

因為是有聲音的SWF檔,原本利用removeChild()移除,但是聲音還在,且不斷重疊上來

google了一下,很多人有這個問題,有興趣的大家,請點入下列連結,觀看解決方法,

https://www.google.com.tw/search?q=removeChild+swf+%E9%9F%B3%E8%A8%8A%E9%82%84%E5%9C%A8&hl=zh-TW&tbo=d&ei=9IgDUdjPHovzkAWl-YGgCw&start=0&sa=N&biw=1821&bih=857

我這邊是用了unloadAndStop(),

(google: https://www.google.com.tw/search?q=unloadAndStop&oq=unloadAndStop&aqs=chrome.0.57&sourceid=chrome&ie=UTF-8)

不過這個方法還是有很多缺點,

(http://ticore.blogspot.tw/2009/05/flash-player-10-unloadandstop-test.html)

 

 

arrow
arrow

    mosquitoyo 發表在 痞客邦 留言(0) 人氣()