2017-10-12 81 views
-3

我开发的代码创建了一个接一个加载swfs的容器,当每个swf完成时它将卸载该swf。那么它会保存你已经加载的swf,并且下次启动时会加载最后一个swf。但遗憾的是我在我的输出:(得到这个为什么我会得到:提供的索引超出界限错误?

的SWFLoader 'loader2'(part2.swf)加载

的SWFLoader 'loader1'(part1.swf)加载

的SWFLoader 'loader4'(第四部分.swf文件)加载

的SWFLoader 'loader3'(part3.swf)加载

所有SWF加载

的SWFLoader 'loader1'(part1.swf)

的RangeError:错误#2006:提供的索引超出范围。

在flash.display使用::级DisplayObjectContainer/getChildAt() 在dblogo()

如何摆脱提供的索引是出界失误? 我新的AS3所以,如果可以把它简单... 下面是代码:

import flash.events.FullScreenEvent; 
import flash.display.StageScaleMode; 

stage.scaleMode = StageScaleMode.EXACT_FIT; 
stage.displayState = StageDisplayState.FULL_SCREEN; 
import com.greensock.*; 
import com.greensock.loading.*; 
import com.greensock.events.LoaderEvent; 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.net.SharedObject; 

import flash.events.MouseEvent; 


var mySO:SharedObject = SharedObject.getLocal("edbfngrwfh"); 
var reza:Number = -1; 
var loaderIndex:Number = -1; 

loaderIndex = mySO.data.my_vis; 
if (!mySO.data.my_vis) { 
loaderIndex = -1; 
} 


if (mySO.data.my_vis == 1) { 
loaderIndex = 0; 
} 


if (mySO.data.my_vis == 2) { 
loaderIndex = 1; 
} 



if (mySO.data.my_vis == 3) { 
loaderIndex = 2; 
} 



if (mySO.data.my_vis == 4) { 
loaderIndex = 3; 
} 





progress_mc.scaleX = 0; 


var currentLoader:SWFLoader; 


var swfs:LoaderMax = new LoaderMax({onComplete:completeHandler,onProgress:progressHandler,onChildComplete:childCompleteHandler}); 


swfs.append(new SWFLoader("part1.swf", {container:this.stage, autoPlay:false})); 
swfs.append(new SWFLoader("part2.swf", {container:this.stage, autoPlay:false})); 
swfs.append(new SWFLoader("part3.swf", {container:this.stage, autoPlay:false})); 
swfs.append(new SWFLoader("part4.swf", {container:this.stage, 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++; 
    trace(loaderIndex); 

    reza = loaderIndex 
    trace(reza); 

    mySO.data.my_vis = loaderIndex; 
    mySO.flush(); 


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


     //can't show stuff that was unloaded so lets stop 

     mySO.clear(); 
    loaderIndex = -1 
    swfs.load(); 
trace("all done everyone gone"); 
removeEventListener(Event.ENTER_FRAME, trackSWFPlayback); 




} else { 
//dynamically reference current loader based on value of loaderIndex 




currentLoader = swfs.getChildAt(loaderIndex); 
trace(currentLoader); 
trace(loaderIndex); 
//make the content of the current loader visible 


currentLoader.content.visible = true; 


    //fade it in 


TweenLite.from(currentLoader.content, 0.1, {alpha:1}); 


//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(); 

//unload the swf that just played 

currentLoader.unload(); 

//set up and play the next swf 


initCurrentLoader(); 


} 
} 

this.addEventListener(Event.ENTER_FRAME, loadSWFs) 



function loadSWFs(e:Event):void{ 
load_btn.visible = false; 
swfs.load(); 
this.removeEventListener(Event.ENTER_FRAME, loadSWFs) 

} 
/* Click to Hide an Object 
Clicking on the specified symbol instance hides it. 

Instructions: 
1. Use this code for objects that are currently visible. 
*/ 
+5

请使用您的巨大智商来正确地设置您的代码。你应该尊重那些愿意帮助的人,而不是把一个脚本乱成一团。然后,启用调试将问题缩小到产生错误的一行,以便帮助者可以专注于错误的本质而不是搜索它。 – Organis

+0

如果有人吹嘘自己的智商,但他们的代码看起来像是完整的newb废话,那就得爱一个人。 – DodgerThud

回答

2

我想你应该与指数开始= 0,而不是-1:VAR loaderIndex:数= 0; 尝试并告诉我们结果

+0

好吧,那工作... greeeeeeeeeeeeeaaaat ...但在下次加载part1.swf后...问题回来.... – Pixier

+0

这就是ittttttttttttttttttttttttttttttt ...它的完成... (loaderIndex == swfs.numChildren - 1)使它完美... tnx您的帮助rezamass ... – Pixier

+0

@Pixier如果这是正确的解决方案,你可以点击接受这个答案? – 3vilguy

相关问题