2016-09-05 3 views
0

は、私は別の後にメインのSWFファイルのいずれかに4つのSWFファイルをロードするコードは、残念ながら私は2つの問題に直面している:part1.swfをロードできないのはなぜですか?

import com.greensock.*; 
import com.greensock.loading.*; 
import com.greensock.events.LoaderEvent; 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.MouseEvent; 

progress_mc.scaleX = 0; 

var loaderIndex:Number = -1; 
var currentLoader:SWFLoader; 

var swfs:LoaderMax = new 

LoaderMax({onComplete:completeHandler,onProgress:progressHandler,onChildComplete:childCompleteHandler}); 

swfs.append(new SWFLoader("part1.swf", {container:container_mc, autoPlay:false})); 
swfs.append(new SWFLoader("part2.swf", {container:container_mc, autoPlay:false})); 
swfs.append(new SWFLoader("part3.swf", {container:container_mc, autoPlay:false})); 
swfs.append(new SWFLoader("part4.swf", {container:container_mc, autoPlay:false})); 




function progressHandler(e:LoaderEvent):void { 
progress_mc.scaleX = e.target.progress; 

}

function childCompleteHandler(e:LoaderEvent):void { 
trace(e.target + " loaded"); 
e.target.content.visible = false; 

}

:ここに私のコードです
function completeHandler(e:LoaderEvent):void { 
trace("all swfs loaded"); 

progress_mc.visible = false; 

initCurrentLoader(); 
addEventListener(Event.ENTER_FRAME, trackSWFPlayback); 

}

function initCurrentLoader() { 

loaderIndex++; 

if (loaderIndex == swfs.numChildren) { 
    //reset back to 0 if the last swf has already played 
    loaderIndex = 0; 
} 

//dynamically reference current loader based on value of loaderIndex 

currentLoader = swfs.getChildAt(loaderIndex); 

//make the content of the current loader visible 

currentLoader.content.visible = true; 

//tell the current loader's swf to to play 

currentLoader.rawContent.gotoAndPlay(1); 

}

function trackSWFPlayback(e:Event):void { 
//trace(currentLoader.rawContent.currentFrame); 

//detect if the loaded swf is on the last frame 

    if (currentLoader.rawContent.currentFrame == currentLoader.rawContent.totalFrames) { 

    trace("swf done"); 

    //hide and stop current swf 
    currentLoader.content.visible = false; 

    currentLoader.rawContent.stop(); 


    //set up and play the next swf 

    initCurrentLoader(); 


} 

}

load_btn.addEventListener(MouseEvent.CLICK, loadSWFs) 

function loadSWFs(e:MouseEvent):void{ 
load_btn.visible = false; 
swfs.load(); 
} 

問題1:それは、アドビフラッシュdoes't負荷で作られていないSWFファイルであるpart1.swf。ここに私が毎回見ることができるエラーがあります:

RangeError:エラー#2006:提供されたインデックスは範囲外です。 flash.displayでdblogo() では、flash.display ::のDisplayObjectContainer/getChildAtで () ::スプライト/ constructChildren()は、flash.display ::スプライト() では、flash.displayで::のMovieClip() dbmovieで() にSWFLoader 'loader2'(part2.swf)がロードされ にSWFLoader 'loader1'(part1.swf)は にSWFLoader 'loader4'(part4.swf)は にSWFLoader 'loader3'(part3.swf)は、すべての をロードロードロードswfsがロードされました swf done

poblem 2:最後のswfを停止するスクリプトがあります。 swfファイルをロードしたいのですが、swfを停止するのではなく、むしろアンロードするほうが巨大です。各swfを停止する代わりにアンロードする方法。 私はまったく新しいフラッシュで、as3はこれらの2つの主要な問題を修正するために私のas3を編集するだけです。 任意任意任意の提案が極端に高く評価されて...どうもありがとう

答えて

0

私は、このチェックが間違っていると信じて - あなただけするnumChildrenが1になる1つのswfファイルを持っているでしょうが、そのインデックスが持つ0

スタートであるかどうインデックス0の代わりに-1:

var loaderIndex:Number = 0; 

そして:SWFファイルとローダーを削除する方法はありアンロードするためとして

if (loaderIndex == swfs.numChildren - 1) // index 0 equals numchildren = 1 
{ 
    //reset back to 0 if the last swf has already played 
    // Why do you reset the index if you only want to play the swfs once ? You should just stop here and remove your enterframe event listener 
    loaderIndex = 0; 
} 

loaderIndex++; 

。 remove(loaderInstance)ただし、ローダーのインスタンスを保持する必要があります。この場合は、loaderIndexを増やす必要はありませんが、常に0にしておいてください。別の方法は、LoaderMaxのすべてのコンテンツを取り除くswfs.dispose()です(この場合、最後のswfの後にのみ行うことができます)演奏された)

関連する問題