Reputation: 3828
I have an array of images that I have loaded into a Loader array. However, I am wondering if this is using up lots of resources to keep on adding images on top of each other.
The goal is when they press the screen it will go to the next image in the array and display it. When it reaches the end it will start over. They have a constant flow of fading images. Again, I am wondering does the addChild in this case keep on adding NEW images to the screen and eventually will have so many on top of each other that it will crash. The final out put is for a mobile app. Do I need to unload the previous image after the new one is loaded or is this not an issue?
Here is my working code:
package com
{
import flash.display.MovieClip;
import flash.display.Stage;
import com.*;
import flash.events.*;
import flash.filesystem.File;
import flash.net.*;
import flash.display.*;
import com.greensock.*;
import com.greensock.easing.*;
//////////////////
public class pictures extends MovieClip
{
public var Images:Array = new Array();
public var RandomImages:Array = new Array();
public var c:int = 0;
public function pictures()
{
loadImages("Joyful","1");
this.addEventListener(MouseEvent.CLICK, displayImages);
}
public function loadImages(Decade:String,Mystery:String)
{
Images = [];
RandomImages = [];
var desktop:File = File.applicationDirectory.resolvePath("RosaryImages/"+Decade+"/"+Mystery);
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{
RandomImages.push("RosaryImages/"+Decade+"/"+Mystery+"/"+files[i].name);
trace(RandomImages[i]);
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest(File.applicationDirectory.url + RandomImages[i]));
Images.push(my_loader);
}
displayImages();
}
public function displayImages(e:Event = null)
{
addChild(Images[c]);
TweenMax.fromTo(Images[c],2, {alpha:0}, {alpha:1, ease:Quint.easeOut} );
if (c < (Images.length) - 1)
{
c++;
}
else
{
c = 0;
}
}
}
}
Upvotes: 0
Views: 163
Reputation: 18747
No, once your entire image set is added as children, repeated addChild()
calls will just bring the DisplayObject in question to the top of your display list, instead of creating another copy. So, no crashes should occur due to the reason you ask.
I don't recommend unloading, but removing from display list, as Lukasz said in comments, is useful to not to waste processing resources.
Upvotes: 1