Hi metSyS,
It looks like you're constantly creating new instances of
MovieMaterial's here. If you do that + add Event listeners, it will
never be cleared from memory. The general rule is that "if you
addEventListener, you MUST removeEventListener" or you'll get memory
leaks.
In your code, you were also creating new loaders for every click. By
using the same loaders many times, you're less likely to get trouble.
A third issue is that you should avoid instantiating objects (other
than the basic types String, Number, int, uint, Boolean) in the class
definition. Move this to the constructor to get reliable results.
Here's how I'd code the class:
package code
{
import away3d.materials.MovieMaterial;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class xmlLoaderModule
{
//--arrays--
//--flashes--
public var swfMaterialArray:Array;
public var timeSwfMaterialArray:Array
//--variables--
private var groupIndex:int = 0;
public var swfLoaded:Boolean = false;
//--XML--
public var xml:XMLList;
private var xmlLoader:URLLoader;
//--booleans--
public var xmlFileLoaded:Boolean = false;
// -- Re-use these across your class
private var swfLoader:Loader;
private var flashMaterial:MovieMaterial;
public function xmlLoaderModule()
{
swfMaterialArray = new Array()
timeSwfMaterialArray = new Array();
xmlLoader = new URLLoader();
swfLoader = new Loader();
}
public function llooaaddiinngg():void
{
xmlLoader.addEventListener(Event.COMPLETE,xmlFileLoadedFunc);
xmlLoader.load(new URLRequest("Sirius-Group.xml"));
}
public function xmlFileLoadedFunc(e:Event):void
{
xmlLoader.removeEventListener(Event.COMPLETE,xmlFileLoadedFunc);
var xmlDataPic:XML=new XML(xmlLoader.data);
xml=xmlDataPic.children();
xmlFileLoaded=true;
}
public function loadingTexture():void
{
for (var i:int=0; i < xml[0].children()
[1].elements("swf").length(); i++) {
swfLoader.load(new
URLRequest(xml[0].children()[1].elements("swf")
[i].attributes()[0]));
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfLoadedFunc);
timeSwfMaterialArray.push(swfLoader.contentLoaderInfo);
}
}
public function swfLoadedFunc(e:Event):void
{
swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfLoadedFunc);
flashMaterial = new MovieMaterial( swfLoader.content,
{interactive:true,smooth:2});
swfMaterialArray[timeSwfMaterialArray.indexOf(e.target)] =
flashMaterial;
swfLoaded = true;
}
}
}
Hope this + my advice can help you nailing the memory issue!
J
--
To unsubscribe, reply using "remove me" as the subject.