Thanks man its working,
can you tell me how it done apart from the attachments in detail, it would be helpful for me further
How can I use the same for future .swf loading & what are the points I need to take into consideration while making key event
When you use addChild to add the loader its class is MainTimeLine, which, in this case, didn't contain the code we needed. To set the timer we need to call a function from the instance of the Timer class in the Game class. Using ApplicationDomain you can create a new instance of the Game class, however that would be futile, as it wouldn't affect the one in the game. Therefore, we need to find the document class (i.e. Main) through the MainTimeLine. We'll use the scanForChildren function in the attachment for this purpose by changing it from:
function scanForChildren(obj:DisplayObjectContainer, depth:int):void {
if(depth > 5) return;
var prefix:String = "";
var j:int = 0;
while(j++ < depth){
prefix += " ";
}
for(var i = 0; i < obj.numChildren; i++){
var child:DisplayObject = obj.getChildAt(i);
if(!child.name.indexOf("instance") == 0) trace(prefix, "[" + i + "]", child.name, "[" + getQualifiedClassName(child) + "]");
if(child is DisplayObjectContainer){
scanForChildren(DisplayObjectContainer(child), depth + 1);
}
}
}
to:
function scanForChildren(obj:DisplayObjectContainer, depth:int):void {
if(depth > 0) return;
var prefix:String = "";
var j:int = 0;
while(j++ < depth){
prefix += " ";
}
for(var i = 0; i < obj.numChildren; i++){
var child:DisplayObject = obj.getChildAt(i);
trace(prefix, "[" + i + "]", child.name, "[" + getQualifiedClassName(child) + "]");
if(child is DisplayObjectContainer){
scanForChildren(DisplayObjectContainer(child), depth + 1);
}
}
}
What changed:
depth > 5 => depth > 0
if(!child.name.indexOf("instance") == 0)
And replace game with mcAnk in the following line in the keyListener function:
scanForChildren(game, 0);
It'll find all the DisplayObjects in MainTimeLine - in this case only the instance of the Main class. To access it we need to call:
DisplayObject(mcAnk.getChildAt(0))For other games you have to use the number given by the scanForChildren function.
From here we access the variable game, which contains the variable timer we were looking for. The function we want to call on timer is Init and the parameter we need to give it is time_total (or however long we want for the level, which doesn't matter as we can reset it as many times as we like). Finally we get:
DisplayObject(mcAnk.getChild(0)).game.timer.Init(DisplayObject(mcAnk.getChild(0)).game.timer.time_total);Which can also be written as:
var game:DisplayObject = DisplayObject(mcAnk.getChild(0));
game.timer.Init(game.timer.time_total);
Note: the reason we can call these functions and variables is because they're public. We can't call functions such as GameCompleted in the class Game.