特别感谢JoãoCésar这个as3代码创建了一个生成SWF加载器的函数。他使用增量值(count)循环遍历存储每个加载器的动态信息的数组。在这种情况下,count%swfs.length将导致0,1,0,1 ... ...以循环顺序有效地加载SWF。
所以这是IDEA:
我如何保存或记住,上次关闭哪个swf文件以及下次从那个swf文件开始...(它应该记住哪个swf已经完成,下次你将从那个swf文件而不是child1开始。 swf)
为此,我使用了SharedObject并尝试保存刚刚加载到变量中的swf文件的数量,但我无法以正确的方式处理它...
由于
以下是代码:
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
var count:uint = 0;
var currentSWFLoader:SWFLoader;
var swf:Object = {};
var swfs:Array =
[
{path:"child1.swf", container:this},
{path:"child2.swf", container:this}
]
function generateSWFLoader(path:String, container:DisplayObjectContainer):SWFLoader
{
return new SWFLoader
(
path,
{
container: container,
y: 100,
onProgress:progressHandler,
onComplete:completeHandler,
autoPlay: false
}
);
}
function loadSWF(index:uint):void
{
if (currentSWFLoader)
currentSWFLoader.dispose(true);
swf = swfs[index];
currentSWFLoader = generateSWFLoader(swf.path, swf.container);
currentSWFLoader.load();
}
function progressHandler(e:LoaderEvent):void
{
bar.scaleX = e.target.progress;
}
function completeHandler(e:LoaderEvent):void
{
e.target.rawContent.play();
addEventListener(Event.ENTER_FRAME, checkFrame);
}
function checkFrame(e:Event):void
{
if (currentSWFLoader.rawContent.currentFrame == currentSWFLoader.rawContent.totalFrames)
{
trace("swf done playing");
removeEventListener(Event.ENTER_FRAME, checkFrame);
loadSWF(++count % swfs.length);
}
}
bar.scaleX = 0;
loadSWF(count % swfs.length);
答案 0 :(得分:0)
以下是有关如何在共享对象中保存变量的一般信息。
package
{
import flash.display.Sprite;
//import the shared object
import flash.net.SharedObject;
public class Main extends Sprite
{
//create and store the shared object
var my_so:SharedObject = SharedObject.getLocal("yourNameOfSharedObject");
public function Main()
{
//un-comment to save or load
//save();
//load();
}
function save(){
//save the number 2 to the shared object in a variable called swfNumber
my_so.data.swfNumber = 2;
}
function load(){
//load the the number stored in swfNumber
var swfNumber = my_so.data.swfNumber;
trace(swfNumber);
}
}
}