Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Clear previous image

Engaged ,
Jun 20, 2013 Jun 20, 2013

I'm showing image from tilelist on mouse click.

but how can i clear previous image on next mouse click?

var XMLSource:String = "imagelist.xml";

var xmlImglist:XML;

var urlLoader:URLLoader = new URLLoader();

var urlRequest:URLRequest;

urlRequest = new URLRequest(XMLSource);

urlLoader.addEventListener(Event.COMPLETE, playlistLoaded);

urlLoader.load(urlRequest);

function playlistLoaded(e:Event):void

{

          xmlImglist = new XML(urlLoader.data);

          for (var i:int=0; i<xmlImglist.BgImgList.length(); i++)

          {

                    trace(i);

                    bgImageList.addItem({source:xmlImglist.BgImgList});

                    bgImageList.addEventListener(Event.CHANGE, showImage);

          }

}

var imgLoader:Loader;

function showImage(e:Event):void

{

          var imagepath:String = bgImageList.selectedItem.source;

          imgLoader = new Loader();

          addChild(imgLoader);

          imgLoader.x = area_mc.x + 1;

          imgLoader.y = area_mc.y + 20;

          imgLoader.load(new URLRequest(imagepath));

}

TOPICS
ActionScript
648
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 20, 2013 Jun 20, 2013

One way would be to use the same Loader instaed of creating a new one every time.  Since a Loader can only hold one object at a time, if you reload the same one with something new, then whatever it was holding beforehand is removed.

Translate
LEGEND ,
Jun 20, 2013 Jun 20, 2013

One way would be to use the same Loader instaed of creating a new one every time.  Since a Loader can only hold one object at a time, if you reload the same one with something new, then whatever it was holding beforehand is removed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 21, 2013 Jun 21, 2013

Try this:

var imgLoader:Loader;

function showImage(e:Event):void

{

          if ( imgLoader ) {             // if was added

               removeChild(imgLoader);    // remove if was added

               imgLoader = null;        // remove from the memory old image

          }

          var imagepath:String = bgImageList.selectedItem.source;

          imgLoader = new Loader();

          addChild(imgLoader);

          imgLoader.x = area_mc.x + 1;

          imgLoader.y = area_mc.y + 20;

          imgLoader.load(new URLRequest(imagepath));

}

each time you call showImage - flash will remove old image and upload new one

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2013 Jun 23, 2013
LATEST

As Ned suggested - reuse the same loader. The code below works if you don't need any transitions.

import flash.display.Loader;

var XMLSource:String = "imagelist.xml";

var imgLoader:Loader;

var xmlImglist:XML;

var urlLoader:URLLoader = new URLLoader();

var urlRequest:URLRequest;

urlRequest = new URLRequest(XMLSource);

urlLoader.addEventListener(Event.COMPLETE, playlistLoaded);

urlLoader.load(urlRequest);

initLoader();

function initLoader():void

{

          imgLoader = new Loader();

          imgLoader.x = area_mc.x + 1;

          imgLoader.y = area_mc.y + 20;

          addChild(imgLoader);

}

function playlistLoaded(e:Event):void

{

          xmlImglist = new XML(urlLoader.data);

 

          for (var i:int = 0; i < xmlImglist.BgImgList.length(); i++)

          {

                    trace(i);

                    bgImageList.addItem({source: xmlImglist.BgImgList});

                    bgImageList.addEventListener(Event.CHANGE, showImage);

          }

}

function showImage(e:Event):void

{

          imgLoader.unload();

          imgLoader.load(new URLRequest(bgImageList.selectedItem.source));

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines