Hi all community and old game i made in 2.0 was sponsored and i have to put this in my game and i dont know how
I try with code and export good but not work some idea how do that?
Thanks
How to use the Kizi preloader
The Kizi preloader is implemented as a separate swf file that receive game load progress data through javascript using the ExternalInterface API. In order to replace your current preloader with the Kizi preloader, take the following steps:
1. If you are using a FlashDevelop style preloader, replace your current Preloader class with the following code :
package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.utils.getDefinitionByName;
import flash.system.Security;
import flash.utils.setTimeout;
public class Preloader extends MovieClip {
public function Preloader()
{
Security.allowDomain("*");
addEventListener(Event.ENTER_FRAME, updateProgress);
if (ExternalInterface.available)
ExternalInterface.addCallback("startGame", startGame);
}
private function updateProgress(e:Event):void
{
// update percents loaded
var total:Number = stage.loaderInfo.bytesTotal;
var loaded:Number = stage.loaderInfo.bytesLoaded;
var pct:int= loaded / total * 100;
// Report to the Kizi preloader about the game file load progress
if (ExternalInterface.available)
{
ExternalInterface.call("setPreloaderProgress", pct );
}
else
{
// No external interface is available (stand-alone mode?), so we need to launch
// the game ourselves
if (pct == 100)
setTimeout(startGame, 1000);
}
// Everything is loaded, we can stop running this event
if (pct == 100)
removeEventListener(Event.ENTER_FRAME, updateProgress);
}
private function startGame():void
{
// hide loader
var mainClass:Class = getDefinitionByName("Main") as Class;
addChildAt(new mainClass() as DisplayObject, 0);
}
}
}
If you’re using Adobe Flash Professional style preloader (first frame’s action) , use the following instead of your current preloader code:
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.utils.setTimeout;
stop();
Security.allowDomain("*");
// hide the play button until the game loads
var percent:Number = 0.0;
var javascript:XML=<script><![CDATA[function(){return true;}]]></script>;
function startGame():void
{
trace("Start Game");
//start the actual game
this.gotoAndStop(2);
}
// called as the game loads and moves the progress bar accordingly
function update(e:Event):void
{
if(loaderInfo)
{
percent = (loaderInfo.bytesLoaded/loaderInfo.bytesTotal) * 100;
if (ExternalInterface.available && ExternalInterface.call(javascript) != null)
{
ExternalInterface.call("setPreloaderProgress", percent );
trace(percent + "percent loaded");
}
else
{
if (percent == 100)
{
startGame();
}
}
if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal)
stage.removeEventListener(Event.ENTER_FRAME, update);
}
}
stage.addEventListener(Event.ENTER_FRAME, update);
if (ExternalInterface.available)
ExternalInterface.addCallback("startGame", startGame);
2. If you’re using the FlashDevelop method, make sure to add code that will launch your game to the startGame function :
private function startGame():void
{
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, updateProgress);
loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
// Here goes code to launch the game
var mainClass:Class = getDefinitionByName("Main") as Class;
addChildAt(new mainClass() as DisplayObject, 0);
}
3. To test your preloader implementation , upload the game to your game sand box and click “Play version (Dynamic Preloader)”
Once you’re satisfied with the result, click on “Release to production” and check the “Use Dynamic Preloader” checkbox.
Links to example implementations:
Flash CS4:
http://kizi.com/api/preloader_cs4.flaFlash CS5:
http://kizi.com/api/preloader_cs5.flaFlashDevelop:
http://kizi.com/api/preloader_fd.zip