I have a container with the following code to load my vr. It all works fine unless you click the close button before the vr has fully loaded. If you do this, the vr continues to autorotate but displays the unloaded faces as grey. An example of the problem can be seen here: http://www.visual360.co.uk/flash32/mp34_loader.html (you have to be quick clicking on the close button so it doesn't finish loading...)
Does any one know how I can sort this out?
Thanks in advance,
MrT
Code: Select all
stop();
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
var loader:Loader;
loader = new Loader();
var url:String="mp16.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);
addChildAt(loader, 0); // add your swf directly to the stage
close.addEventListener(MouseEvent.CLICK,close_pano);
function close_pano(e:Event):void {
gotoAndStop(2);
if (vr.pano) {
vr.pano.bmpTile[0].dispose();
vr.pano.bmpTile[0] = null;
vr.pano.bmpTile[1].dispose();
vr.pano.bmpTile[1] = null;
vr.pano.bmpTile[2].dispose();
vr.pano.bmpTile[2] = null;
vr.pano.bmpTile[3].dispose();
vr.pano.bmpTile[3] = null;
vr.pano.bmpTile[4].dispose();
vr.pano.bmpTile[4] = null;
vr.pano.bmpTile[5].dispose();
vr.pano.bmpTile[5] = null;
loader.mouseChildren = false;
vr.pano.cleanup();
removeChild(loader);
vr.pano = null;
loader.unloadAndStop();
}
}
full.addEventListener(MouseEvent.CLICK,close_pano_and_full);
function close_pano_and_full(e:Event):void {
gotoAndStop(2);
var link:URLRequest = new URLRequest("http://www.visual360.co.uk/southamerica/machupicchu/mp16_full.html");
navigateToURL(link);
if (vr.pano) {
vr.pano.bmpTile[0].dispose();
vr.pano.bmpTile[0] = null;
vr.pano.bmpTile[1].dispose();
vr.pano.bmpTile[1] = null;
vr.pano.bmpTile[2].dispose();
vr.pano.bmpTile[2] = null;
vr.pano.bmpTile[3].dispose();
vr.pano.bmpTile[3] = null;
vr.pano.bmpTile[4].dispose();
vr.pano.bmpTile[4] = null;
vr.pano.bmpTile[5].dispose();
vr.pano.bmpTile[5] = null;
loader.mouseChildren = false;
vr.pano.cleanup();
removeChild(loader);
vr.pano = null;
loader.unloadAndStop();
gotoAndStop(2)
}
}