Skip to main content
Participant
July 21, 2006
Answered

Help! Remove Movie Clips

OK...here's my problem... I am making a portfolio site and I have my thumbnails being created dynamically through XML...very similar to the galleries example in the Sample and Tutorials. Only problem is that I have multiple keyframes with different thumbnails that need to be displyed through a different XML file. I got it to work but the thumbnails from the first frame are still showing on the second frame...How do I remove the dynamically created movie clips?
This topic is closed to new replies. Start a new post to keep the conversation going.
blemmoCorrect answer
Inspiring
July 21, 2006
You must save the number of items so you can use it in the next button. Add a var to the timeline, or maybe another global:

_global.mccount = 0;

In createGallery(), assign the number of thumbnails to this:

_global.mccount = gallery_array.length;

Then you can use this number in the next button:

next_btn.onRelease= function() {
for (var i=0; i<_global.mccount; i++){
_root["image"+i+"_mc"].removeMovieClip();
}
gotoAndStop(2);
}

cheers,
blemmo

5 replies

02TransAmAuthor
Participant
July 21, 2006
You are awesome!!!! Seriously you are an Action Script Genious!!!!! Thank you sooooo much!!!!!! I worked perfectly!!!! How'd you get so good? Any tips?
Translate
02TransAmAuthor
Participant
July 21, 2006
Thanks, I am going to try it!!!!!!!
Translate
02TransAmAuthor
Participant
July 21, 2006
OK...here's the code...At thebottom of the document, I need to remove the clips created on the next button. This is the same code from the gallery sample file; I just added my own XML file.


stop();

import mx.transitions.*;

_global.thisX = 30;
_global.thisY = 70;

_global.stageWidth = 600;
_global.stageHeight = 400;

var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success:Boolean) {
try {
if (success) {
var images:Array = this.firstChild.childNodes;
var gallery_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
gallery_array.push({src:images .firstChild.nodeValue});
}
displayGallery(gallery_array);
} else {
throw new Error("Unable to parse XML");
}
} catch (e_err:Error) {
trace(e_err.message);
} finally {
delete this;
}
};

gallery_xml.load("gallery_practices2.xml");

function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
for (var i = 0; i<galleryLength; i++) {
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
mcLoader_mcl.loadClip(gallery_array
.src, thisMC);
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
if ((i+1)%5 == 0) {
_global.thisX = 20;
_global.thisY += 80;
} else {
_global.thisX += 80+20;
}
}
}

var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};

mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
};

mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 2;
var marginWidth:Number = 8;
evt.scale = 8;
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.endFill();
evt._xscale = evt.scale;
evt._yscale = evt.scale;
evt._rotation = Math.round(Math.random()*-10)+5;
evt.onPress = function() {
this.startDrag();
this._xscale = 30;
this._yscale = 30;
this.origX = this._x;
this.origY = this._y;
this.origDepth = this.getDepth();
this.swapDepths(this._parent.getNextHighestDepth());
this._x = (_global.stageWidth-evt._width+30)/2;
this._y = (_global.stageHeight-evt._height+30)/2;
mx.transitions.TransitionManager.start(this, {type:mx.transitions.Photo, direction:0, duration:1, easing:mx.transitions.easing.Strong.easeOut, param1:empty, param2:empty});
};

evt.onRelease = function() {
this.stopDrag();
this._xscale = this.scale;
this._yscale = this.scale;
this._x = this.origX;
this._y = this.origY;
};

evt.onReleaseOutside = evt.onRelease;
};

mcLoader_mcl.addListener(mclListener);

next_btn.onRelease= function() {
gotoAndStop(2);
}
back_btn.onRelease= function() {
gotoAndStop(1);
}
Translate
blemmoCorrect answer
Inspiring
July 21, 2006
You must save the number of items so you can use it in the next button. Add a var to the timeline, or maybe another global:

_global.mccount = 0;

In createGallery(), assign the number of thumbnails to this:

_global.mccount = gallery_array.length;

Then you can use this number in the next button:

next_btn.onRelease= function() {
for (var i=0; i<_global.mccount; i++){
_root["image"+i+"_mc"].removeMovieClip();
}
gotoAndStop(2);
}

cheers,
blemmo
Translate
Inspiring
July 21, 2006
Do a removeMovieClip() for the MCs not needed anymore, or maybe make them invisible by setting the _visible property to false when you want to reuse them later. This should be done when the frame is entered, so you could place this on the frame's script (assumes that the clips are called "thumb0","thumb1" etc. and placed in _root):

for (var i=0;i<mccount;i++){
_root["thumb"+i].removeMovieClip();
//_root["thumb"+i]._visible = false;
}

hth,
blemmo
Translate