对标题感到抱歉,我不确定如何用几句话解释这个。
我查看了谷歌搜索,发现人们在使用预加载器时在第2帧导出类时更容易找到它。我目前正在使用通常的方法,使第1帧与预加载器,第2帧与资产持有人和游戏的大部分,第3帧有停止();行动。这是我为了获得有效的预加载器AS Gamer所遵循的教程。
经过几个小时的搜索后,我才发现人们使用导出第2帧而不是传统的资产持有者来提及和撤销,但没有示例或教程。
有没有人知道我在哪里可以找到一个带有示例代码的教程我参考了第2帧预加载器的导出?
答案 0 :(得分:2)
我一直想写一个关于预加载器主题的完整教程,但我仍然处于启动新网站的过程中......直到那时,这里有高光:
将需要两部分 -
javascript方面的一个:将flashvars发送到预加载器,并将flash对象嵌入到html结构中。我喜欢swfobject的简单性和防弹性。
HTML:
<html>
<head>
<script type="text/javascript" src="/javascript/swfobject/swfobject.js"></script>
<script type="text/javascript" src="/javascript/logic.js"></script>
</head>
<body>
<div id="flashContainer">content for when swfobject fails</div>
</body>
</html>
logic.js:
var _flashvars =
{
filePath : "/flash/swf/yourcontent.swf",
FR : "60",
verbose : "false",
SW : "760",
SH : "550"
};
var _params =
{
quality : 'high',
menu : 'false',
base : '/flash/swf/'
};
var _attr =
{
id : "flashContainer"
};
function embedSWF()
{
swfobject.embedSWF(
"/flash/preLoader.swf",
"flashContainer",
"760",
"550",
"9.0.0",
"/javascript/swfobject/expressInstall.swf",
_flashvars,
_params,
_attr
);
return;
}
//onload event
embedSWF()
在闪光灯方面,我们有preloader fla(或者你正在构建它)。它有目的地“内容不可知”,因为我重复使用它来进行所有预加载。你可以通过在闪存变量中进行硬编码来节省一些时间。无论如何,我有两个班 -
Main.as - 在运行时拉入flashvars,启动加载,然后响应加载进度,最后将加载的内容添加到显示列表中。
Preloader.as - 完成所有重任。
请注意,这些是直接从我的项目中提取的部分类,我只包含了必需品(您必须完成代码并根据需要进行定制)。
另请注意,这是执行此操作的众多方法之一;)
Main.as:
package {
public class Main extends MovieClip
{
private var _loadParams :Object;
private var _filePath :String;
private var _frameRate :uint;
private var _stageH :Number;
private var _stageW :Number;
private var _verbose :Boolean;
public function Main():void
{
super();
if (stage)
{
init();
}
else
{
this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
}
/**
* once preloader is onstage, create param object.
* assign vars from param object
*
* stage height / stage width:
* some files may have SH and SW defined, if they are, used them as
* stage dimensions. If they are not, default to current stageHeight,Width
*
* @param e
*/
private function init(e:Event = null):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, init);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_loadParams = new Object();
_loadParams = LoaderInfo(stage.loaderInfo).parameters;
_filePath = String( parseParam( "filePath", "undefined.swf" ) );
_frameRate = uint( parseParam( "FR", "24" ) );
_stageH = Number( parseParam( "SH", String(stage.stageHeight) ) );
_stageW = Number( parseParam( "SW", String(stage.stageWidth) ) );
( String( parseParam( "verbose", "true" )) == "true")?_verbose = true : _verbose = false;
initiateLoader();
}
private function parseParam(name:String, defaultValue:String):String
{
if (_loadParams.hasOwnProperty(name) && _loadParams[name] != "" && _loadParams[name] != "undefined")
{
return _loadParams[name];
}
else
{
return defaultValue;
}
}
private function initiateLoader():void
{
_loader = new PreLoader(_filePath, _verbose);
_loader.addEventListener("displayObjectLoaded", onLoadComplete, false, 0, true);
this.addEventListener(Event.ENTER_FRAME, setLoadPercentage, false, 0, true);
}
/**
* respond to load graphically
*/
private function setLoadPercentage(e:Event):void
{
_loadPercentage = Math.round((_loader.progressNumberArray[0] /_loader.progressNumberArray[1])*100);
if (_verbose)
{
_txt.text = String(_loadPercentage) + "% Loaded";
}
}
/**
* finally, add the loader object into the display list.
*/
private function onLoadComplete(evt:Event):void
{
_loader.removeEventListener("displayObjectLoaded", onLoadComplete);
this.removeEventListener(Event.ENTER_FRAME, setLoadPercentage);
this.addChild(_loader);
}
Preloader.as
package {
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.text.TextField;
public class PreLoader extends Sprite {
private var _loader : Loader;
private var _loaderInfo : LoaderInfo;
private var _verbose : Boolean = false;
private var _loadProgressString : String = "";
private var _bytesLoaded : Number = 0;
private var _bytesTotal : Number = 0;
public function PreLoader(path:String, verbose:Boolean)
{
_verbose = verbose;
_loader = new Loader();
_loaderInfo = _loader.contentLoaderInfo;
// there are several other events to listen for and respond to
_loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress, false, 0, true);
_loaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
try
{
_loader.load(new URLRequest(path));
}
catch (evt:Error)
{
_loader.unload();
var errMsg:TextField = new TextField();
with (errMsg) {
width = 300;
text = "Unable to load content:\n" + evt.toString();
}
addChild(errMsg);
dispatchEvent(new Event("displayObjectLoaded"));
}
}
private function onProgress(evt:ProgressEvent):void
{
var loadPercent:int = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100);
_bytesLoaded = evt.bytesLoaded;
_bytesTotal = evt.bytesTotal;
_loadProgressString = (loadPercent + " % loaded: " + _bytesLoaded + " bytes of " + _bytesTotal + " total bytes");
if (_verbose)
{
trace(_loadProgressString);
}
}
private function onComplete(evt:Event):void
{
_loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
_loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
addChild(_loader);
dispatchEvent(new Event("displayObjectLoaded"));
}
/**
* getter for load details
*/
public function get progressNumberArray():Array
{
return [_bytesLoaded,_bytesTotal];
}
希望这有助于您入门。如果您有任何问题,请告诉我。
喝彩!