1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| import mx.xpath.XPathAPI;
//récupération variable passée en paramètre
var gameId;
gameId=this.idgame;
var gamePath:String="jeu/jeu.swf";
var debug;
var isLoaded:Boolean;isLoaded=false;
var compteur:Number=0;
var IntervalID;
//-----------------------------------------
//chargement du XML de configuration
var myXml:XML = new XML();
var niveau;
var gain;
var itemsCol=new Array();
myXml.ignoreWhite = true;
myXml.onLoad = function(success:Boolean) {
if (success) {
gamePath=XPathAPI.selectSingleNode(this.firstChild ,"root/gamePath").firstChild;
niveau =XPathAPI.selectSingleNode(this.firstChild,"root/niveau").firstChild;
gain =XPathAPI.selectSingleNode(this.firstChild,"root/gain").firstChild;
//parcours de la liste des items.
var itemsNode = XPathAPI.selectNodeList(this.firstChild,"root/items/item");
for (var i = 0; i < itemsNode.length; i++) {
itemsCol.push(itemsNode[i].firstChild);
}
trace("success!"+ gain + " " + niveau+ " " + gamePath);
_root.isLoaded=true;trace("isLoaded= "+isLoaded);
}
}
myXml.onHTTPStatus = function(httpStatus:Number) {
trace("onHTTPStatus :" + httpStatus);
}
myXml.load("../loadXML.xml");
IntervalID=setInterval(this,"testIsLoaded",10);
function testIsLoaded(){
compteur++;
trace(compteur);
if (isLoaded){
clearInterval(IntervalID);
loadGame();
}
}
function loadGame(){
trace("debut");
mcl.loadClip(gamePath, movieContener);
}
//barre de preloading
var loader:MovieClip=attachMovie("loader","loader_mc",1);
loader._width=150;
loader._height=30;
loader._x=Stage.width/2-loader._width/2;
loader._y=Stage.height/2-loader._height/2;
Stage.align = "TL";
createEmptyMovieClip("movieContener", this.getNextHighestDepth());
var mclListener:Object = new Object();
//ecouteur de resize de la scene
var StageListener:Object = new Object();
StageListener.onResize = function() {
movieContener._height = Stage.height;
movieContener._width = Stage.width;
};
Stage.addListener(StageListener);
//preloader
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._height = this.Stage.height;
target_mc._width = this.Stage.width;
trace("mc onLoadInit");
}
mclListener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
loader.moveMe(bytesLoaded / bytesTotal);
loader.swapDepths(this.getNextHighestDepth());
this.txt.text="loaded" + bytesLoaded + " " + bytesTotal;
}
mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String, httpStatus:Number){
this.txt.text="error" + errorCode + " " + httpStatus;
}
mclListener.onLoadStart = function(target_mc:MovieClip) {
this.txt.text="onLoadStart";
}
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(mclListener); |
Partager