在更大的闪存阶段插入迷你游戏?

时间:2013-08-16 07:12:59

标签: actionscript-3 flash actionscript

我对这件事情很陌生,所以如果答案显而易见,我很抱歉。 我在flash中制作了几个800 * 640像素的迷你游戏,我想知道是否有任何方法可以将这些包含在主舞台中,即1024 * 768,如果可以在两个阶段之间传递一些变量的值,用于评分目的。

1 个答案:

答案 0 :(得分:0)

插入外部SWF:

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad() {
    var loader:Loader = new Loader();
    var URLreq:URLRequest = new URLRequest("directory\\minigame1.swf");

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);

    loader.load(URLreq);
}

function onCompleteHandler(event:Event) {
    movieclip.addChild(event.currentTarget.content);
    movieclip.x = (stage.stageWidth - movieclip.width) / 2;
    movieclip.y = (stage.stageHeight - movieclip.height) / 2;
}

function onProgressHandler(event:ProgressEvent) {
    var percent:Number = event.bytesLoaded / event.bytesTotal;
}

startLoad();

您可以使用LocalConnection两个 SWF之间传递数据:

// Sender - minigame1 script
var lcs:LocalConnection = new LocalConnection();
lcs.send("local_connection1_name", "function_name", "minigame1", 100);

// Receiver - 'master' script
var lcr:LocalConnection = new LocalConnection();
lcr.connect("local_connection1_name");
lcr.client = this;



function function_name(mg:String,score:int):void {
    trace(mg + ": " + score)
}