Skip navigation
Currently Being Moderated

Clean up memory after movie has played.

Aug 10, 2012 4:07 PM

Tags: #memory #swf #external #load

I have a as3 application that has multiple frames with embed flvs. Based on the value from an xml file, a specific frame is selected and the movie is played. When the choose another link the flv is stoped and another is played automatically. This is not elegant but it worked fine until i realised that the sound for any video will go when memory hit about 160 mb in the projector file. What i want to know is:

 

  1. how do i clean up memory after a video has finished playing since this seems to be tied to the sound going after 160 mb of usage.
  2. If this is not possible how can i remove an external swf file that is nested in a another movie clip example: detailContainer.movieHolder.

 

ie (I figure if the memory cannot be cleaned up after an embed file has finished playing then i will have to load swf file and unload . i have loaded files already, but unloading is the problem)

 
Replies
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2012 5:28 PM   in reply to jahflasher

    you should have only one flvplayback component in one frame and assign its source property based on links chosen

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 13, 2012 3:25 PM   in reply to jahflasher

    try:

     

     

     

        var myImageLoader:Loader;

        var myImageRequest:URLRequest;

        var theImagePath:String;

     

     

        //part from xml processor function

        

        theImagePath = "flash/"+myXML..item_video_link[n];

        loadTheMovie(theImagePath);

     

     

        function loadTheMovie(theImagePath):void{

    if(myImageLoader){

    if(myImageLoader.content){

         myImageLoader.unloadAndStop();

    }

       if(detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.numChi ldren !=0){

         detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);             

        } 

        myImageLoader = new Loader();

        myImageRequest= new URLRequest(theImagePath);

        myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);

        myImageLoader.load(myImageRequest);

        detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);

     

        }

      

        function showMeTheVideo(evt:Event):void{

    // not sure what you want to do here, if anything.

    }

     

     

     

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 13, 2012 9:46 PM   in reply to jahflasher

    use:

     

     

        var myImageLoader:Loader;

        var myImageRequest:URLRequest;

        var theImagePath:String;

     

     

        //part from xml processor function

        

        theImagePath = "flash/"+myXML..item_video_link[n];

        loadTheMovie(theImagePath);

     

     

        function loadTheMovie(theImagePath):void{

    if(myImageLoader){

    if(myImageLoader.content){

         myImageLoader.unloadAndStop();

    }

       if(myImageLoader.stage){

         detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);             

        } 

        myImageLoader = new Loader();

        myImageRequest= new URLRequest(theImagePath);

        myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);

        myImageLoader.load(myImageRequest);

        detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);

     

        }

      

        function showMeTheVideo(evt:Event):void{

    // not sure what you want to do here, if anything.

    }

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 8:17 AM   in reply to kglad

    use:

     

     

     

        var myImageLoader:Loader;

        var myImageRequest:URLRequest;

        var theImagePath:String;

     

     

        //part from xml processor function

        

        theImagePath = "flash/"+myXML..item_video_link[n];

        loadTheMovie(theImagePath);

     

     

        function loadTheMovie(theImagePath):void{

    if(myImageLoader){

    if(myImageLoader.content){

         myImageLoader.unloadAndStop();

     

    if(myImageLoader.stage){

         detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);             

    }

        myImageLoader = new Loader();

        myImageRequest= new URLRequest(theImagePath);

        myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);

        myImageLoader.load(myImageRequest);

        detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);

     

        }

      

        function showMeTheVideo(evt:Event):void{

    // not sure what you want to do here, if anything.

    }

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 9:07 AM   in reply to jahflasher

    the code i suggested could not trigger that error.  make sure you're using the code you quoted in your previous message.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 12:05 PM   in reply to jahflasher

    the number of children is not relevant to the code i suggested.

     

    the code i suggested removes your loaded swf from the display list and stops the swf (if you're publishing for fp 10 or better). 

     

    but you're probably reloading the same swf after doing that.   ie, when you call loadTheMovie  you must change the argument passed in the loadTheMovie function call or you'll see the same swf load.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 3:05 PM   in reply to jahflasher

    what fp version are you publishing for?

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 5:26 PM   in reply to jahflasher

    when you execute that code do you see "attempting to unload" and "attempting to remove from memory"?

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 9:42 PM   in reply to jahflasher

    then something you're not showing in this forum is causing a problem. 

     

    make sure there's no other code.  in fact, create a new fla that contains just that code and the minimum movieclips to compile that code.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 15, 2012 8:35 AM   in reply to jahflasher

    whoa, where'd that setInterval come from?

     

    that's what's causing your problem.  you're creating runaway loops.

     

    either clear that interval before setting it or use setTimeout.

     

    p.s.  please mark helpful/correct responses.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 15, 2012 9:07 AM   in reply to jahflasher

    using the trace function should allow you to pinpoint your problem.  if you watched the trace output of your test fla you should have noticed multiple calls to loadTheMovie after the first setInterval executed.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 15, 2012 10:05 AM   in reply to jahflasher

    most likely the code is working.  you're just not seeing what you expect.

     

    for example, the setInterval problem didn't prevent the code i suggested from working correctly.  it was working correctly.  you just failed to see what you expected.  you were expecting loadTheMovie to be called once every 5 seconds while you were actually calling it 2,3,4 etc times after 10,15,20 etc seconds.

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 15, 2012 11:31 AM   in reply to jahflasher

    the main swf must be published for fp 10 or better for unloadAndStop to work.  if unloadAndStop is used that will stop video streams.

     

    otherwise, you can use the removedfromstage event in your loaded swf(s) to stop video play when the swf is unloaded.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points