A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: replace content?

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849

    replace content?

    Yep, I've just gotten my official copy of Flash CS3, so instead of answering stupid questions I'll be asking them.

    This morning I was experimenting with preloading, and noticed that if I loaded an external file and put it into an existing movie clip using addChild, it would place it into the movie clip, but not replace the previous contents. So the original movie clip elements would still be there, the timeline would still run, etc.

    I realize I could create a new, blank movie clip and put the loaded content in there, but humor me here: Is there a way to completely replace the contents of an existing clip with something else?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    When you load an external file you usually use the Loader class. Then all you do is use the same loader object and replace the content with the new one. Just somewhere you create it once.

    Regarding movieclips you need to remove them. addChild will automatically create a new higher level.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Hmm. Well I suppose the newer way has its benefits, but so far I much prefer the old method that just replaced the content of a clip entirely. I'll have to experiment with it more. Thanks for the info.

  4. #4
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    If you have a movieclip named MC, with some contents in it, on the stage, this will remove it:
    var MC:MovieClip = new MovieClip();

    I think that should do it though.. not much of an AS3-expert, but been writing some the last days
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

  5. #5
    Senior Member
    Join Date
    Oct 2002
    Location
    Newfoundland
    Posts
    131
    So if you create a loader object on line one of your main timeline, and call the same loader within functions on the same frame, will it load into the same object??

    This AS3 is a very difficult changeover...

  6. #6
    Senior Member
    Join Date
    Oct 2002
    Location
    Newfoundland
    Posts
    131
    I am having a problem similar to Rdoyle.. I have various images loading into a MC on my stage, each image has a link attached to it and is loaded by the same loader class... when I do a trace and click on the image, it also traces the images that were loaded previously as if they are all on top of one another...

    Here is a snippet of the code that contains the problem...


    stop();
    var loader:URLLoader = new URLLoader();
    var mainXML:XML = new XML();
    loader.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("featuredVacations.xml"));
    one.addEventListener(MouseEvent.CLICK, oneV);
    two.addEventListener(MouseEvent.CLICK, twoV);
    three.addEventListener(MouseEvent.CLICK, threeV);
    four.addEventListener(MouseEvent.CLICK, fourV);
    var imageLoader:Loader = new Loader();


    function oneV(event:MouseEvent):void {
    imageLoader.unload();
    var imageRequestOne:URLRequest = new URLRequest(mainXML.path[0].text());
    imageLoader.load(imageRequestOne);
    imageLoader_mc.addChild(imageLoader);
    imageLoader_mc.addEventListener(MouseEvent.CLICK, goHereOne);
    function goHereOne(event:MouseEvent):void {
    trace("ImageOne!");
    }
    }

    function twoV(event:MouseEvent):void {
    imageLoader.unload();
    var imageRequestTwo:URLRequest = new URLRequest(mainXML.path[1].text());
    imageLoader.load(imageRequestTwo);
    imageLoader_mc.addChild(imageLoader);
    imageLoader_mc.addEventListener(MouseEvent.CLICK, goHereTwo);
    function goHereTwo(event:MouseEvent):void {
    trace("ImageTwo!");
    }
    }



    -------------------------------------------------------
    I've been working on this problem for days and can't figure it out!! Any help is appreciated BIGTIME!!

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I don't understand exactly what you are doing there, but every time one, two etc is clicked you add another imageLoader: imageLoader_mc.addChild(imageLoader); They will pile up on top of each other. Just create the imageLoader only once and then load and unload it or when you do it the way you did removeChild first.
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    Senior Member
    Join Date
    Oct 2002
    Location
    Newfoundland
    Posts
    131
    Hey thanks for the reply... I didn't realize that by calling "imageLoader_mc.addChild(imageLoader);" it would create a new loader every time... I thought my loader was created once at the start and just called to add the child...

    Sorry for being so behind on this... but can you give me an example as to how to call my loader so it replaces what is currently on the stage?


    ...soon be time for a trip to the bookstore I think!

  9. #9
    Senior Member
    Join Date
    Oct 2002
    Location
    Newfoundland
    Posts
    131
    I've added the removeChild you mentioned, and have the same problem....

    function oneV(event:MouseEvent):void {
    removeChild(imageLoader);
    var imageRequestOne:URLRequest = new URLRequest(mainXML.path[0].text());
    imageLoader.load(imageRequestOne);
    addChild(imageLoader);
    imageLoader.addEventListener(MouseEvent.CLICK, goHereOne);
    function goHereOne(event:MouseEvent):void {
    //trace(mainXML.path[0].attributes());
    trace("ImageOne!");
    }
    }

    function twoV(event:MouseEvent):void {
    removeChild(imageLoader);
    var imageRequestTwo:URLRequest = new URLRequest(mainXML.path[1].text());
    imageLoader.load(imageRequestTwo);
    addChild(imageLoader);
    imageLoader.addEventListener(MouseEvent.CLICK, goHereTwo);
    function goHereTwo(event:MouseEvent):void {
    //trace(mainXML.path[1].attributes());
    trace("ImageTwo!");
    }
    }

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is a simple example. You don't even need to unload:
    PHP Code:
    var myLoader:Loader = new Loader();
    addChild(myLoader);
    var 
    imageRequest:URLRequest = new URLRequest("images/a0.jpg");
    myLoader.load(imageRequest);
    var 
    count:uint 0;
    myBut.addEventListener(MouseEvent.CLICK,addImages);
    function 
    addImages(ev:MouseEvent)
    {
        
    count++;
        var 
    imageRequest:URLRequest = new URLRequest("images/a"+count+".jpg");
        
    myLoader.load(imageRequest);

    - The right of the People to create Flash movies shall not be infringed. -

  11. #11
    Senior Member
    Join Date
    Oct 2002
    Location
    Newfoundland
    Posts
    131
    Awesome ... Thanks C.I., I can't tell you how much I appreciate it... I would have left here bald today having ripped out all of my hair if I never got this working...

    Thanks again, I owe you a beer!

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