Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 145345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:24:26+00:00 2026-05-11T08:24:26+00:00

In Flash CS4, I’m creating a photo gallery. My goal is to load different

  • 0

In Flash CS4, I’m creating a photo gallery. My goal is to load different thumbnails from a number of images. I have managed that when one clicks an image, a number of thumbnails are being displayed, but when one clicks another image, the new thumbnails are placed on top of the old ones. Can someone help me on how to get rid of the old thumbnails?

Here is the code:

for (var i:int = 0; i < thumbnails.length(); i++) {   imgLoader.unload();   imgLoader = new Loader();   imgLoader.load(new URLRequest(thumbnails[i]));   imgLoader.name= i;   imgLoader.x =  95 * columns;   imgLoader.y = 80 * rows;   imgLoader.alpha = 0;   details.gallery.addChild(imgLoader);    if (columns+1< 5) {     columns++;   } else {     columns = 0;     rows++;   } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:24:27+00:00Added an answer on May 11, 2026 at 8:24 am

    This is where an Array is your friend. You could do this without an array by merely using a while loop to remove every last child from the sprite or movieclip that you added the thumbs to. The reason we use arrays is so that we can reuse the thumbs, instead of reloading them we merely remove them from the display list. You push a reference to each object into an array for each thumb as you add it to the display list. Each thumbContainer node in the XML gets its own array which get added to the main array. The main array holds references to thumbnail arrays. Thumbnail arrays hold references to loaded thumbnails so that they can be added and removed from the display list. If you plan to never use the thumbs after they have been seen once you may set it’s reference equal to null, otherwise merely remove it from the display list; There is no reason to load it many times. When you are ready to add the new thumbs you must clear out previous thumbs. The easiest way to do this is with a while loop.

    //Assuming the thumbs were loaded into container while(container.numChildren > 0) {     //Remove the first child until there are none.     container.removeChildAt(0); }  //The XML / 2 Containers / thumbContainer[0] and thumbContainer[1] 

    <?xml version='1.0' encoding='utf-8'?> <xml>     <thumbContainer>         <thumb path='path/to/file' />         <thumb path='path/to/file' />         <thumb path='path/to/file' />     </thumbContainer>     <thumbContainer>         <thumb path='path/to/file' />         <thumb path='path/to/file' />         <thumb path='path/to/file' />     </thumbContainer> </xml> 

    package {     import flash.display.Sprite;     import flash.events.Event;     import flash.events.MouseEvent;     import flash.net.URLLoader;     import flash.net.URLRequest;      public class DocumentClass extends Sprite     {         private var _container:Sprite;         private var _mainArray:Array;         private var _xml:XML;         private var _urlLoader:URLLoader;         private var _urlRequest:URLRequest;          public function DocumentClass():void         {             if(stage) _init();             else addEventListener(Event.ADD_TO_STAGE, _init, false, 0 , true);         }         private function _init(e:Event = null):void         {             //Will contain arrays for each thumbContainer in the XML.             _mainArray = [];              _urlRequest = new URLRequest('path/to/xml');             _urlLoader = new URLLoader();             _urlLoader.addEventListener(Event.COMPLETE, _onXMLComplete, false, 0, true);               }         private function _onXMLComplete(e:Event):void         {             _xml = new XML(e.target.data);              _loadThumbs(0);         }         private function _loadThumbs(pIndex:int):void         {             _clearThumbs();              //Find out how many sets of thumbs there and add to _mainArray             for(var i:int = 0; i < _xml.thumbContainer.length(); i++)             {                 var tempArray:Array = new Array();                  for(var j:int = 0; j < _xml.thumbContainer[i].thumb.length; j++)                 {                     tempArray[i].push(_xml.thumbContainer[i].thumb[j].@path);                 }                 _mainArray.push(tempArray);             }               //Here is where we add the new content to container, or you can call a function to do it.         }         private function _clearThumbs():void         {             while(container.numChildren > 0)             {                 //Remove the first child until there are none.                 container.removeChildAt(0);             }         }     } } 

    Again, it is good practice to hold a reference to something that is reusable and to simply remove it from the display list instead of setting to null and prepping for garbage collection only to be loaded again later. I already have written more than I intended and wasn’t able to slap in all the code I wanted. It is important to setup the code that makes sure it only loads a particular set of thumbs once; That is the whole idea. As for removing them, it’s as simple as the while loop I showed you, you just need to know the name of the DisplayObjectContainer that parents them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It is fine in hidden fields. It is only required… May 11, 2026 at 11:15 am
  • added an answer the .NET 2.0 sdk tool TLBIMP can create an assembly… May 11, 2026 at 11:15 am
  • added an answer When your server encounters an error in production mode, it… May 11, 2026 at 11:15 am

Related Questions

In flash you can open a file on the user's computer. In flash 9
In Flash, I can prompt the user for a location to save a file
PNG images appear fuzzy in flash CS3. They are very blocky and appear unanti-aliased
I've so far dabbled in Flash doing 1-man shows for quite some time, but
I'm making a small quiz-application in Flash (and ActionScript 3). Decided to use the
Make a new AS3 Document in Flash, paste in the following code and run
I'm researching game development in Flash and Flex. I've downloaded the Flex Builder trial
I'm looking for advice on how to dynamically create content in flash based on
How do you reference a bitmap on the stage in flash using actionscript 3?
How do you trigger a javascript function using actionscript in flash? The goal is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.