Pergunta

so i have this photo gallery with 2 external classes, this code is the timeline code that calls the classes in to import the gallery and make it work. So far so good, the problem starts when i want to put this photo gallery in a media presentation or website or something with more than 1 layer, it happens that the gallery stays there after being called and increases more gallery's every time i return to that frame with the code.

So i was wondering if its possible create some simple code to add to this one thats says to remove the gallery if im not on frame number 13 or stop calling the classes if im not on that specific frame, something like that. I tried the "removeChild", it solved half of the problem, it didnt quite removed the gallery but at least stoped the increasing effect.

All i need is a way to remove the gallery when i go to another frame/page. Can someone help me?

import flashfold.as3.*;

var imgLoader:ImageLoader;

var thumbsToLoad:Array=[];

var menuColumnItems:int=6;

var menuTotItems:int=30;



var menuThumbs:Vector.<Bitmap>=new Vector.<Bitmap>();

var menuBigPics:Vector.<String>=new Vector.<String>();


var menu:SpinnerMenu;

btnSpin.visible=false;

errorBox.wordWrap=true;

errorBox.visible=true;

errorBox.text="Loading thumbnails...";

populatePics();

prepImgs(thumbsToLoad);

function prepImgs(a:Array):void {

imgLoader=new ImageLoader();

imgLoader.addEventListener(ImageLoader.LOAD_ERROR,errorLoading);

imgLoader.addEventListener(ImageLoader.IMGS_LOADED,allLoaded);

imgLoader.loadImgs(a);

}

function errorLoading(e:Event):void {

errorBox.visible=true;

errorBox.text="There has been an error loading images. The server may be busy."; 

}

function allLoaded(e:Event):void {

errorBox.visible=false;

initApp();

}


function initApp():void {

var i:int;

for (i=0; i<menuTotItems; i++) {

    menuThumbs[i]=imgLoader.bitmapsArray[i];

}

menu=new SpinnerMenu(menuThumbs,menuBigPics,menuColumnItems);



this.addChild(menu);
trace("oi");

menu.x=72;

menu.y=50;





menu.menuInfoBox.x=160;

menu.menuInfoBox.y=90;


this.transform.perspectiveProjection.fieldOfView=70;

this.transform.perspectiveProjection.projectionCenter=new 
        Point(menu.x+menu.menuWidth/2,menu.y+menu.menuHeight/2);

btnSpin.visible=true;

//We load the initial image.

menu.loadInitial();

 }

 function populatePics():void {

var i:int;

for (i=1; i<=menuTotItems; i++) {

    thumbsToLoad[i-1]="small"+String(i)+".jpg";
}

for (i=1; i<=menuTotItems; i++) {

    menuBigPics[i-1]="pic"+String(i)+".jpg";

trace('ok');


btnSpin.addEventListener(MouseEvent.CLICK, spinMenu);

function spinMenu(e:MouseEvent):void {

    var r:Number=Math.random();

    if (r<0.5) {

        menu.doSpin("right");

    } else {

        menu.doSpin("left");
    }
     }
    }
 }
Foi útil?

Solução

if imgLoader is the gallery that you want deleted then this should help:

if (objectParent.getChildByName("imgLoader") != null) {
     trace("imgLoader exsits");
     objectParent.removeChild("imgLoader");
}

Basically this is checking if imgLoader exist and if it does, it removes it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top