为什么它不加载part1.swf?

时间:2016-09-05 14:59:00

标签: actionscript-3 flash load

我有一个代码,一个接一个地将4个swf文件加载到主swf文件中,但不幸的是我遇到了2个问题:这是我的代码:

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:part1.swf是一个不用adobe flash制作的swf文件,不会加载。这是我每次都能看到的错误:

RangeError:错误#2006:提供的索引超出范围。     在flash.display :: DisplayObjectContainer / getChildAt()     在dblogo()     在flash.display :: Sprite / constructChildren()     在flash.display :: Sprite()     在flash.display :: MovieClip()     在dbmovie() 加载了SWFLoader'loading2'(part2.swf) 加载了SWFLoader'loading1'(part1.swf) 加载了SWFLoader'loading4'(part4.swf) 加载了SWFLoader'loading3'(part3.swf) 所有swfs加载 swf完成

poblem 2:我的脚本中有一行停止了最后一个swf。因为我想加载可能很大的swf文件我宁愿卸载而不是只是停止swfs。如何卸载每个SWF而不是停止它。  因为我是flash的新手,所以每个人都可以编辑我的as3来解决这两个主要问题。 任何任何建议都非常感谢...非常感谢

1 个答案:

答案 0 :(得分:0)

我相信这个检查是错误的 - 如果你只有一个swf,numChildren将是1,但它的索引将是0.

从索引0开始,而不是-1:

var loaderIndex:Number = 0;

然后:

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++; 

至于卸载有一种方法可以使用swfs.remove(loaderInstance)删除加载器,但是你需要保留加载器的实例。在这种情况下,你不需要增加你的loaderIndex但总是保持为0.另一种方法是swfs.dispose(),它将摆脱你的LoaderMax中的所有内容(在这种情况下你只能在最后一个swf之后执行此操作)饰)