簡體   English   中英

如何將外部.swf預加載器與實際.swf結合?

[英]How to combine external .swf preloader with actual .swf?

我有一個.swf文件,可以加載游戲中的外部.swf文件。 有沒有辦法將兩個瑞士法郎合並為一個? 這是.swf中加載外部游戲的代碼:

import flash.display.*;
import flash.net.*;
import flash.events.*;

var array:Array = new Array ("Loading Bugs..","Everyone hates loading screens..","Lovely day, isn't it?", 
"Want instant updates? Follow us on Twitter!", "A game where you can kill bugs, pretty cool...huh?"); //create an array of possible strings
var randomIndex:int = Math.floor ( Math.random () * array.length ); //generate a random integer between 0 and the length of the array
loading_txt.text = array [ randomIndex ]; //put the random string in your text field
var myRequest:URLRequest = new URLRequest("insectGame.swf");

var myLoader:Loader = new Loader();
myLoader.load(myRequest);

function showProgress(evt:ProgressEvent):void 
{

    txtPreloader.text = Math.round((evt.bytesLoaded/evt.bytesTotal)*100) + "%";


    mcPreloaderBar.width = Math.round(evt.bytesLoaded/evt.bytesTotal * 200);    
}

function showLoaded(evt:Event):void 
{
    myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,showProgress);
    myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,showLoaded);
    removeChild(txtPreloader);
    removeChild(mcPreloaderBar);
    removeChild(mcPreloaderFrame);
    removeChild(Mosquito);
    removeChild(loading_txt);
    mcPreloaderBar = null;
    mcPreloaderFrame = null;
    txtPreloader = null;
    loading_txt = null;
    addChild(myLoader);
}

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoaded);

您可能要在主swf文件的第一幀中實現預加載器。 因此,您應該擁有實際的.swf的來源。 如果您使用的是Flash Builder,請簽出mxmlc編譯器的-frame參數。

此方法的核心思想是將預加載器分配為應用程序的主類,再向swf文件添加1幀,並且您不直接實例化gameClass。 當內容完全加載(framesLoaded == totalFrames)您可以使用以下代碼創建游戲類的實例:

var gameClass:Class = Class(getDefinitionByName("GameClass"));
if(gameClass)
{
 var app:Object = new gameClass();
 addChildAt(app as Sprite, 0);
}

這是有用的鏈接: http : //www.drewing.de/blog/2009/09/23/building-a-preloader-with-actionsscript-3-using-mxmlc-and-the-frame-pragma/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM