0

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");
    }
     }
    }
 }
Mars
  • 3
  • 1

1 Answers1

0

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.

whodeee
  • 617
  • 5
  • 18
  • thanks a lot, but it didnt work, i guess its menu that i have to remove, it gives me this error: 1120: Access of undefined property objectParent. oh i forgot to mention that im working in flash cs4, flash player 10.1 AS 3.0, i dont know, but it migh have some code changes sintax, maybe its that – Mars May 16 '13 at 16:50
  • `objectParent` should be changed to whatever the parent is of your `imgLoader` either `stage` or `this` or wherever the `imgLoader` is added to. – whodeee May 16 '13 at 18:02
  • if you want to remove the menu, the it is the same basic code as above `if (this.getChildByName("menu") != null) { trace("menuexsits"); this.removeChild("menu"); }` should work for you to remove the menu – whodeee May 16 '13 at 18:05
  • great! Please mark the answer as correct to help others and possibly upvote my previous comment if that helped as well :-) – whodeee May 17 '13 at 16:55