0

some if don't work well for some reason which is this if part:

if (mc.main.avatar.contains(my_loader) == true) {
    mc.main.avatar.removeChild(my_loader);        
}

this is the whole part of if i need it to work:

if (varfromphp !="")
{
    if (mc.main.avatar.contains(my_loader) == true) {
        mc.main.avatar.removeChild(my_loader);
    }

    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest(varfromphp + "?n=" + Math.random() ));
    mc.main.avatar.addChild(my_loader);
    mc.main.avatar.buttonMode = true;
    mc.main.avatar.avatar_bg_mc.visible = false;        

} else {
    mc.main.avatar.avatar_bg_mc.visible = true;
}

this code is in setInterval so it happens in loop after minute and half and what i want is to remove image the loader loaded everytime this run and add the new one based on the "varfromphp" variable every time it loops.

the problem is when i place the if i mentioned above at the top of loader. the loader dont load and i bet the whole code after inside this if dont happen like making the bg invisible dont happen... and if i added it before addchild the old loaded image is not removed and new one is overlayed on the old one.... and ofc if i placed the if at the bottom logically everything work but the added child will be removed as normal. so what i do???

akmozo
  • 9,829
  • 3
  • 28
  • 44
Wild Lion
  • 53
  • 9
  • 1
    You need to hold reference to my_loader from outside of the setInterval call. Where's the code for setInterval? – Karmacon Jul 17 '15 at 23:24
  • i tried doing this adding var my_loader:Loader = new Loader(); outside the setinteval but the old load didnt remove. just the new image is overlayed on old imgae but old one didnt get removed. any idea? – Wild Lion Jul 18 '15 at 07:15
  • u were true @ karma thanks alot :) – Wild Lion Jul 18 '15 at 08:51
  • 1
    Adobe said : Instead of using the [`setInterval()`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setInterval()) method, consider creating a [**`Timer`**](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html) object, with the specified interval, using 0 as the repeatCount parameter (which sets the timer to repeat indefinitely). – akmozo Jul 18 '15 at 12:14
  • thanks. i will do so – Wild Lion Jul 18 '15 at 16:58

0 Answers0