Copy link to clipboard
Copied
Hello!
I have made a xml slide show where the pictures move on and off of the stage when the user clicks next. But after so many pictures it freezes up. From my understanding something like garbage collection needs to happen but I guess the data contained in the slideshow, such as the pictures that are no longer on the screen, are not seen as "garbage collectable".
I am not sure what code to post to better help someone understand - I have 145 lines of code - but I am attaching the code here if someone is generous to look at it! I have attached a CS4 AS3 document and a text doc if you are not able to read that one.
Would you be able to help me with this? Even if you could tell me what to look at to figure it out that would be nice!
Tks! O
here's one way to do what i just described:
...
oluc wrote:
Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:
var rawImage:String;
var imgData:XML;
var lastImageIndex:int = 0;
var imageLoader:Loader;
var imgNum:int;
var imageLoaderHost: MovieClip;
public function packagedF(e:Event = null):void {
rawImage = imgData.image[imgNum].imgURL;
lastImageIndex = imgData.*.length() - 1;
rawW = imgData.image[imgNum].imgW;
rawH = imgData.image[
Copy link to clipboard
Copied
you need to remove all references to objects you want gc'd, you need to remove all listeners attached to those objects, remove the objects from the displaylist, stop all streams (which doesn't apply to a bitmap display) and finally assign the object to null.
Copy link to clipboard
Copied
Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:
var rawImage:String;
var imgData:XML;
var lastImageIndex:int = 0;
var imageLoader:Loader;
var imgNum:int;
var imageLoaderHost: MovieClip;
public function packagedF(e:Event = null):void {
rawImage = imgData.image[imgNum].imgURL;
lastImageIndex = imgData.*.length() - 1;
rawW = imgData.image[imgNum].imgW;
rawH = imgData.image[imgNum].imgH;
master_mc = new MovieClip;
master_mc.x = 0;
master_mc.y = 166.4;
addChild(master_mc);
imageLoaderHost = new MovieClip ;
imageLoader = new Loader ;
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
imageLoader.load(new URLRequest(rawImage));
master_mc.addChild(imageLoaderHost);
imageLoaderHost.addChild(imageLoader);
imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;
imageLoaderHost.x = 1780;
TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});
TweenMax.from(imageLoader, 1.5, {blurFilter:{blurX:100}});
imageLoader.scaleX = .75;
imageLoader.scaleY = .75;
clearInterval(imgNum);
clearInterval(lastImageIndex);
}
public function loadCompleteHandler(event:Event) {
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);
imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectionDropoff:2});
}
public function nextImgF(e:MouseEvent):void {
// Button glows on and off:
TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut});
//Moves image currently on screen forward to bring on next picture:
TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});
imgNum = imgNum < lastImageIndex ? imgNum + 1:0;
// Refers to function to bring on next picture
packagedF();
}
Copy link to clipboard
Copied
my post was not contingent on anything including how you load your bitmaps.
but, to clarify, you load using a loader. in your case, imageLoader. to what timeline you add imageLoader is irrelevant for this discussion, as far as i can see.
i can see that you're removing a listener that's applied to your loader's contentLoaderInfo property. but you're not nulling your loader so it's not ready for gc. i'm not sure you removed it from its parent, either which would also prevent it from being gc'd.
Copy link to clipboard
Copied
Okay I see. So I guess my question really is: How do I remove my pictures from the display list if they are all loaded from one loader in one movieclip? In looking at my code I don't see a way to remove the pics without removing the whole thing that makes the pictures display - which would mean that slideshow would not work any more. Or, how do I null the loader without making the whole gallery not work any more?
The user has to have the capability to go back to any image that he saw previously. So if I remove an image, I would have to make it so the user could still ref an earlier pic.
Does that make sense or am I off?
Or, is there a way to transfer the pictures to another mc and make that "GCable" as the pictures go into it - or something like that?
Copy link to clipboard
Copied
every time you call packagedF(), you create a new loader. they all have the same reference name so that may be confusing but, you are creating one new loader each time packagedF() is called. if you only call packagedF() once each time your swf is displayed, then you are creating one loader.
to ready that loader for gc, you need to remove it from its parent and then null it (in addition, to removing that listener which you've already done):
imageLoader.parent.removeChild(imageLoader); // these 2 line should only be executed just prior to creating a new loader or, when you no longer need to display the loaded bitmap.
imageLoader=null;
Copy link to clipboard
Copied
here's one way to do what i just described:
oluc wrote:
Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:
var rawImage:String;
var imgData:XML;
var lastImageIndex:int = 0;
var imageLoader:Loader;
var imgNum:int;
var imageLoaderHost: MovieClip;
public function packagedF(e:Event = null):void {
rawImage = imgData.image[imgNum].imgURL;
lastImageIndex = imgData.*.length() - 1;
rawW = imgData.image[imgNum].imgW;
rawH = imgData.image[imgNum].imgH;
master_mc = new MovieClip;
master_mc.x = 0;
master_mc.y = 166.4;
addChild(master_mc);
imageLoaderHost = new MovieClip ;
if(imageLoader!=null){
imageLoader.parent.removeChild(imageLoader);
imageLoader=null;
}
imageLoader = new Loader ;
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
imageLoader.load(new URLRequest(rawImage));
master_mc.addChild(imageLoaderHost);
imageLoaderHost.addChild(imageLoader);
imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;
imageLoaderHost.x = 1780;
TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});
TweenMax.from(imageLoader, 1.5, {blurFilter:{blurX:100}});
imageLoader.scaleX = .75;
imageLoader.scaleY = .75;
clearInterval(imgNum);
clearInterval(lastImageIndex);
}
public function loadCompleteHandler(event:Event) {
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);
imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectio nDropoff:2});
}
public function nextImgF(e:MouseEvent):void {
// Button glows on and off:
TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut});
//Moves image currently on screen forward to bring on next picture:
TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});
imgNum = imgNum < lastImageIndex ? imgNum + 1:0;
// Refers to function to bring on next picture
packagedF();
}
Copy link to clipboard
Copied
kglad, thank YOU very much! That definitely removes it.
If I wanted to remove it after it goes off stage shouldn't I be able to do this:
if (imageLoader.x == -1500 && imageLoader!=null) {
imageLoader.parent.removeChild(imageLoader);
imageLoader=null;
}
I tried it but with the x position at 50 and it did not remove. Do you know what I am missing/doing wrong?
TIA
Copy link to clipboard
Copied
Or what about this!? I tried this after lots of other trial and error and it moves it off the stage but I am not sure if it is removing the pic..
if ( imageLoader!=null && imageLoader.parent.x < 60) {
imageLoader.parent.removeChild(imageLoader);
imageLoader=null;
}
Copy link to clipboard
Copied
if you want to remove the loader after it moves to a certain position, you have the repeatedly check if the loader's at that position. but if you create another loader with the same name before removing and nulling your previous loader, you'll have problems.
Copy link to clipboard
Copied
Oh, I see. So I would have to rewrite all of the code to do something like - put the nulling in a loop and somehow make the name different for each new loader created and make that recognizable by the nulling loop too?
Copy link to clipboard
Copied
i don't know that you need to rewrite any significant part of your code but, you'll need to rewrite some. if you want to remove a loader after one of your tweens complete, there's probably an onComplete property of your tween you can use.
Copy link to clipboard
Copied
I tried onComplete and then removing the loader and I also tried onComplete then function which lead to a constructor that removed. The only thing is that the next picture starts comming on the stage before the previous one is fully off and so when I do that it waits till the image is all the way off the screen and then loads the next image but there are a couple of seconds with blank screen which I am trying to avoid. Otherwise that would have worked beautifully.
Copy link to clipboard
Copied
Any other ideas?
Copy link to clipboard
Copied
what are you trying to do?
Copy link to clipboard
Copied
I have a gallery - right now, after going through about 80 pictures when the flash is exported, the flash starts to chug and freeze up. I have over 200 pictures in the gallery but I cant get past 80! I am trying to make it so that when a picture goes off of the stage to the left, it is gotten rid of so that the computer does not have useless computation of the picture that is not on the screen. The only thing is that I have all of the pictures loading through one loader and one starts to come on the stage as the other goes off (so they are both on the stage at the same time for a little bit). So, I am not able to remove the loader without getting rid of the picture that is comming on the stage. Does that make sense? If not pls let me know and I can explain differently. ![]()
Copy link to clipboard
Copied
:
var rawImage:String;
var imgData:XML;
var lastImageIndex:int = 0;
var imageLoader:Loader;
var imgNum:int;
var imageLoaderHost: MovieClip;
public function packagedF(e:Event = null):void {
rawImage = imgData.image[imgNum].imgURL;
lastImageIndex = imgData.*.length() - 1;
rawW = imgData.image[imgNum].imgW;
rawH = imgData.image[imgNum].imgH;
master_mc = new MovieClip;
master_mc.x = 0;
master_mc.y = 166.4;
addChild(master_mc);
imageLoaderHost = new MovieClip ;
imageLoaderHost.imageLoader = new Loader() ;
imageLoaderHost.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
imageLoader.load(new URLRequest(rawImage));
master_mc.addChild(imageLoaderHost);
imageLoaderHost.addChild(imageLoader);
imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;
imageLoaderHost.x = 1780;
TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});
TweenMax.from(imageLoader, 1.5, {blurFilter:{blurX:100}});
imageLoader.scaleX = .75;
imageLoader.scaleY = .75;
clearInterval(imgNum);
clearInterval(lastImageIndex);
}
public function loadCompleteHandler(event:Event) {
imageLoaderHost.imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);
imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectio nDropoff:2});
}
public function nextImgF(e:MouseEvent):void {
// Button glows on and off:
TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut}); //Moves image currently on screen forward to bring on next picture:
// using an onCompleteParams is important
TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut,onComplete:removeF,onCompleteParams:[imageLoaderHost]});
imgNum = imgNum < lastImageIndex ? imgNum + 1:0;
// Refers to function to bring on next picture
packagedF();
}
function removeF(mc:MovieClip){
mc.parent.removeChild(mc);
mc=null;
}
Copy link to clipboard
Copied
Hey, Thanks a ton! I used the onComplete and onCompleteParams. I have a question on the onCompleteParams: What does it mean "An Array of parameters to pass the onComplete function"? I think I specifically do not understand the term "pass".
Maybe I will understand this next question after I understand the above but...
Would you mind explaining the mc.parent.removeChild(mc)? From what get, with onCompleteParams tells the onComplete that it is dealing with the imageLoaderHost so when the removeF function gets executed thats what it's dealing with - the imageLoaderHost. Now, the imageLoaderHost is an mc, so does the mc in mc.parent..... link to the imageLoaderHost? and if so, how does it recognize to do that?
I have one more question after this but I'll save it. ![]()
Thanks in advance!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more