【问题标题】:why it does't load part1.swf ?为什么它不加载 part1.swf ?
【发布时间】:2017-01-12 23:34:50
【问题描述】:

我有一个代码可以将 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 'loader2' (part2.swf) 已加载 SWFLoader 'loader1' (part1.swf) 已加载 SWFLoader 'loader4' (part4.swf) 已加载 SWFLoader 'loader3' (part3.swf) 已加载 已加载所有 swf 瑞士法郎完成

问题 2:我的脚本中有一行停止了最后一个 swf 。因为我想加载可能很大的 swf 文件,所以我宁愿卸载而不是仅仅停止 swfs 。如何卸载每个 swf 而不是停止它。 因为我对 Flash 和 as3 完全陌生,所以每个人都可以简单地编辑我的 as3 来解决这两个主要问题。 任何任何任何建议都非常感谢......非常感谢

【问题讨论】:

    标签: actionscript-3 flash load


    【解决方案1】:

    我认为这个检查是错误的 - 如果你只有一个 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 拥有播放)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2019-12-16
      • 2011-06-28
      • 2020-06-25
      相关资源
      最近更新 更多