A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Movie Clip - load and unload() image

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    15

    Movie Clip - load and unload() image

    Hi,

    I have a function when a button is clicked an image is loaded into the movie clip:

    var imageLoader:Loader;
    function loadImage(url:String):void {

    imageLoader = new Loader();
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(Pro gressEven t.PROGRESS, imageLoading);
    imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLE TE, imageLoaded);
    }
    loadImage("images/" + image + ".jpg");

    function imageLoaded(e:Event):void {

    movieclip_mc.addChild(imageLoader);
    }


    Is there a way I can remove the previous image from the movie clip before loading the next one? - so replacing the image with the new one when clicked. (the movie clip starts of empty)

    I am struggling to make unload() work. When I use the unload() method - no image appears - but using the trace function the button clicked is recognised.

    Hope some one can help.

    Looking forward to hearing from you.

    Many thanks

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You create the Loader once and add it to the movieclip. Then images will be automatically replaced.

    var imageLoader:Loader = new Loader();
    movieclip_mc.addChild(imageLoader);


    function loadImage(url:String):void
    {
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, imageLoading);
    imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imageLoaded);
    }
    loadImage("images/" + image + ".jpg");

    function imageLoaded(e:Event):void
    {
    //whatever you want to do
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    15
    Thank you so much cancerinform for your help that worked perfectly!

    Many thanks

    Quote Originally Posted by cancerinform View Post
    You create the Loader once and add it to the movieclip. Then images will be automatically replaced.

    var imageLoader:Loader = new Loader();
    movieclip_mc.addChild(imageLoader);


    function loadImage(url:String):void
    {
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, imageLoading);
    imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imageLoaded);
    }
    loadImage("images/" + image + ".jpg");

    function imageLoaded(e:Event):void
    {
    //whatever you want to do
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center