特别感谢JoãoCésar此 as3 代码创建一个函数来生成 SWF 加载器。他使用增量值(计数(循环遍历存储每个加载器的动态信息的数组。在这种情况下,计数 % swfs.length 将导致 0, 1, 0, 1...有效地以循环顺序加载 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);
下面是有关如何在共享对象中保存变量的一些常规信息。
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);
}
}
}