memory problems

Q&A about the latest versions
Post Reply
mrt
Posts: 56
Joined: Mon May 19, 2008 1:22 pm

Hi all,

I'm (still!) re-making my home page in flash. It shows thumbnails which open the corresponding panorama in a central area of the page. I've noticed the the first time you load a panorama it runs smoothly but each panorama you load afterwards gradually scrolls less and less smoothly.

After search these pages, I've narrowed the problem down to memory usage building up each time a new panorama is loaded. I've confirmed this by opening Task manager and viewing the memory usage stats. It goes up by about 30MB with each pan you load.

The panoramas load via a container swf which has the following code in frame 1

Code: Select all

import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
var loader:Loader;
loader = new Loader();
var url:String="mp10.swf";
var urlReq:URLRequest = new URLRequest(url);
var vr:MovieClip; // panorama movieclip

// This is done after the swf is loaded.
function finished_loading (e:Event) {
}

function initHandler(event:Event):void {
	trace("initHandler: " + event);
	vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
	
}

function initPanorama(e:Event) {
// check if the panorama object is available and initialize it
	if ((vr!=null) && (vr.pano!=null)) {
		removeEventListener( Event.ENTER_FRAME , initPanorama);
		vr.pano.setWindowSize(900,412); // resize the window
		vr.pano.setWindowPos(0,63); // reposition
	}
}
// call initPanorama every frame
addEventListener( Event.ENTER_FRAME , initPanorama);

// Tell the loader to call 'finished_loading' after the swf is loaded.
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finished_loading);
// Tell the loader to call 'initHandler' after the swf is initialized.
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loader.load(urlReq);
addChild(loader); // add your swf directly to the stage
Then frame 2 contains two buttons which have the following codes assigned to them.

Code: Select all

stop();

close.addEventListener(MouseEvent.CLICK,close_pano);

function close_pano(e:Event):void {
	removeChild(loader);
	gotoAndStop(3)

}


full.addEventListener(MouseEvent.CLICK,close_pano_and_full);

function close_pano_and_full(e:Event):void {
	removeChild(loader);
	gotoAndStop(4)

}
Frame three just contains a "stop" command

and frame 4:

Code: Select all

import flash.net.URLVariables;
import flash.net.URLRequest;
stop();



var link:URLRequest = new URLRequest("http://www.visual360.co.uk/southamerica/machupicchu/mp10_full.html");
navigateToURL(link); 
I've put removeChild(loader); in to get rid of the panorama but it's not doing the job.

Any suggestions as to how I can sort this out? I haven't looked into using skins as going down this route wouldn't permit navigation around my portfolio from my initial flash homepage.

Thanks in advance,

Nick
User avatar
thomas
Chief Gnome
Posts: 2613
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

you need to call the cleanup() method as described in the API. http://gardengnomesoftware.com/wiki/Pano2VR_-_Flash_API
MfG, Thomas
Smourt
Posts: 170
Joined: Wed Aug 05, 2009 11:15 am

Excuse me for being a bit dim... how do you encorporate this into the tour?

Regards
Stephan
Post Reply