Hi all,
I have a main movie in which I load two types of external movies, pages and themes.
My main swf slows down which each click of one of the menu items. I’ve tried garbage collecting by doing and unloadAndStop for the external swf’s but that does even put a dent in the flash player memory usage as shown by System.totalMemory trace.
A theme will load in an empty movie clip(acting as a container) on the stage, then a page will load in another empty movie clip on the stage.
For example, pageContiainer movie clip will receive page1.swf. themeContainer will receive themeNeutral.swf.
I’m thinking this should not be an issue, as each movie clip simply receives an external swf, which is then replaced by another external swf upon a given load command.
But I can’t seem to get the looaded SWF(s) out of memory and the System.totalMemory just keeps going up and up.
Here are my loaders:
var themeLoader:Loader=new Loader();
themeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, themeLoaded);
var mcTheme:MovieClip;
function themeLoaded(e:Event):void
{
containerTheme.addChild(themeLoader);
mcTheme = themeLoader.content as MovieClip;
}
var pageLoader:Loader=new Loader();
pageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, pageLoaded);
var mcPage:MovieClip;
var pageExitAnimTimeLine:TimelineLite = new TimelineLite({paused:true});
function pageLoaded(e:Event):void
{
containerPage.addChild(pageLoader);
mcPage = pageLoader.content as MovieClip;
//animation in for loaded page
pageExitAnimTimeLine.append(TweenLite.from(mcPage, 1, {y:100, autoAlpha:0, ease:Back.easeOut}));
pageExitAnimTimeLine.play();
}
On the home page are two buttons, when the user clicks one, a theme must load and so must a page. However, I don’t want the page to load until the theme is loaded, hence I add an event listener within the load function:
fun
ction loadAboutUsAfterNeutralThemeLoad(e:MouseEvent):void
{
themeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, delayLoad);
function delayLoad():void
{
//remove listener
themeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, delayLoad);
pageLoader.load ( new URLRequest( "ccgiAboutUs.swf" ) );
}
}
Incidentally, themes must load depending on what the user clicks once inside the main site.
Yes, I could place all the themes in the main.swf, and just externally load the pages, but that would significantly increase the kb of main and I don’t see, with all of AS3’s capabilities, why I should have to do that.
I think my code is causing a substantial memory leak that I can’t seem to plug…any help would be appreciated
p.s. here is a memory display function, you may be able to use it in the future:
var memTimeline:TimelineMax = new TimelineMax({repeat:-1, repeatDelay:0.7});
memTimeline.append( TweenMax.to(this, 0.1, {onComplete:showMemUsedByFlashPlayer}));
function showMemUsedByFlashPlayer():void
{
trace(int((System.totalMemory/Math.pow((1<<10),2))*100)/100); //shows MB rounded to two decimal places
}