Hi
I am trying to load an swf into another swf as part of a course. I try to pass in some parameters to the getData function within the new swf but an error is show,
I am testing by hardcoding values where I would normally use variables. The definitionsArray is where the problem lies.
I tested the new game by harcoding the values instead of passing them in and it was loaded successfully. However when I send the same details to the SAME FUNCTION of getData game from the container/ loader it throws the above error. The ERROR is thrown on the code highlighted below.
Cheers if you are able to have a quick look. Spent two days on the xml and this and learnt loads but now I'm stuck big time.
Código ActionScript :
main body of code of the loader swf
private function xmlGameDataLoadComplete(e:Event):void
{
xmlGameData = XML(e.target.data);
var objectList:XMLList = XMLList(xmlGameData.object);
this.definitionsArray = new Array();//an array of objects and sounds
//Hard code in the definitionsArray
this.definitionsArray = new Array();
this.definitionsArray.push({ mc:"Apple", sound:"AppleSound" });
this.definitionsArray.push({ mc:"Banana", sound:"BananaSound" });
this.definitionsArray.push({ mc:"Bread", sound:"BreadSound" });
this.definitionsArray.push({ mc:"Cake", sound:"CakeSound" });
this.definitionsArray.push({ mc:"Water", sound:"WaterSound" });
this.definitionsArray.push({ mc:"Tomato", sound:"TomatoSound" });
this.definitionsArray.push({ mc:"Sandwich", sound:"SandwichSound" });
this.definitionsArray.push({ mc:"Pizza", sound:"PizzaSound" });
this.definitionsArray.push({ mc:"Pear", sound:"PearSound" });
this.definitionsArray.push({ mc:"Orange", sound:"OrangeSound" });
dataReadyF();
}
private function dataReadyF():void
{
//booleans to tell which type of game to play - they trace fine
trace(xml.lesson.(@id=="1").game[0]);//trace check = undefined
if (xml.lesson.(@id=="1").game[0].@getDataHigh == undefined)
{
var getDataBool:Boolean = true;
var getDataHighBool:Boolean = false;
}
else
{
getDataHighBool = true;
getDataBool = false;
}
//loaderF("../"+xml..lesson.(@id==starLesson).gamesRoute+xml..lesson.(@id==starLesson).game[0],getDataBool,getDataHighBool)
loaderF("../../games/"+xml.lesson.(@id=="1").game[0],getDataBool,getDataHighBool);
trace("../../games/"+xml.lesson.(@id=="1").game[0]);
}
public function loaderF(urlS:String,sendDataB:Boolean=false,sendDataHighB:Boolean=false):void
{
if (loader.content)
{
loader.unloadAndStop(true);
}
this.sendDataBool = sendDataB;
trace(this.sendDataBool);
this.sendDataHighBool = sendDataHighB;
trace(this.sendDataHighBool);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);
loader.load(new URLRequest(urlS));
trace("urlS="+urlS);// ../../animalDragAS3.swf ie: up two levels from revisionKids1.swf
}
private function loadCompleteF(e:Event):void
{
this.libraryRouteX = "library/food.swf";
if (this.sendDataBool)
{
MovieClip(e.target.loader.content).getData(this.libraryRouteX,definitionsArray);//ERROR;
}
if (this.sendDataHighBool)
{
// MovieClip(e.target.loader.content).getDataHigh(1,1);
}
this.addChild(e.target.loader);
}
}
}
code function targeted inside loaded swf game
public function getData(libreria:String, matriz:Array) {
this.definitionsArray = matriz;
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
var loader:Loader = new Loader();
var req:URLRequest = new URLRequest("../"+libreria);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onAssetsLoaded);
try{
loader.load(req, context);
}catch(e:Error){
trace("Asset load error: " + e);
}
this.levelFinal_mc.avatar_mc.gotoAndStop(this.avatarID + 1);
} 