Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure if this is the entire reason behind what you're observing... but for starters, "thumbloader3" and "container3" are scoped locally to the loadThumbs3() method, which means once you finish executing the function, Flash's handles to those objects are lost (not to mention being in an entirely different scope)... try creating class-level properties for those two. Once that's done you should be able to successfully remove them from the stage later on.</p> <p>I hope that you're also properly destroying your objects, and for the sake of brevity you just chose to omit that code above.</p> <p>I've edited the code you had above &amp; put the properties into the proper scope. (the multiple copies of thumbLoader3 are now collected inside of a vector (specialized array) so that they can be properly addressed when it comes time to destroy them)</p> <p>I also wrote you a proper destroy method. ;)</p> <p>I haven't tried it on my own machine, but give it a spin &amp; see how it goes.</p> <pre><code>var images3:Array = ["ad_bona1.jpg", "ad_bona2.jpg", "ad_darkhawk1.jpg", "ad_darkhawk2.jpg"]; var thumbX3:Number = -375; var thumbY3:Number = 220; // begin new instance properties.. // created a new property, allowing you to group (and hold on to) the multiple thumbLoaders var thumbLoader3Vector:Vector.&lt;Loader&gt; = new Vector.&lt;Loader&gt;(); var container3:Sprite; // end new instance properties var loader3:Loader = new Loader(); loader3.load(new URLRequest("assets/ad_bona1.jpg")); addChild(loader3); loader3.alpha = 0; loadThumbs3(); function loadThumbs3():void { // this is where container3 used to be declared container3 = new Sprite(); addChild(container3); container3.buttonMode = true; for(var i3:uint = 0; i3 &lt; images3.length; i3++) { var tPtr:int = thumbLoader3Vector.length; thumbLoader3Vector.push(new Loader()); // this is where thumbLoader3 used to be declared &amp; instantiated thumbLoader3Vector[tPtr].load(new URLRequest("assets/thumbs/" + images3[i3])); thumbLoader3Vector[tPtr].x = thumbX3; thumbLoader3Vector[tPtr].y = thumbY3; thumbX3 += 85; container3.addChild(thumbLoader3Vector[tPtr]); thumbLoader3Vector[tPtr].addEventListener(MouseEvent.CLICK, thumbClicked3); } } function thumbClicked3(event:MouseEvent):void { var path3:String = event.currentTarget.contentLoaderInfo.url; path3 = path3.substr(path3.lastIndexOf("/") + 1); loader3.load(new URLRequest("assets/" + path3)); } ///PROBLEM BELOW, button removes only "loader3" and not the other two for some reason invis_button.addEventListener(MouseEvent.CLICK, unload_loaders); function unload_loaders(event:MouseEvent):void{ // since the thumbLoader3 Loaders are children of container3 in the display list, we need to remove them first for(var $i:uint = 0;$i&lt;thumbLoader3Vector.length;$i++) { removeChild(thumbLoader3Vector[$i]); // also make sure you remove the listener, so that the object will be picked up by garbage collection thumbLoader3Vector[$i].removeEventListener(MouseEvent.CLICK, thumbClicked3); } // and then just set the entire vector to null thumbLoader3Vector = null; // remove the loader3 object &amp; set it to null removeChild(loader3); loader3 = null; // remove the container3 object &amp; set it to null removeChild(container3); container3 = null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload