dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: how do I use unloadAndStop FLV?

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    12

    how do I use unloadAndStop FLV?

    I have several buttons which load an external swf into a loader.
    Here is the code for three of the buttons:


    Code:
    reelButton.addEventListener(MouseEvent.CLICK, reel);
    function reel(event:MouseEvent):void {
    	var reelLoader:Loader = new Loader();
    	addChild(reelLoader);
    	var url:URLRequest = new URLRequest("reel.swf");
    	reelLoader.load(url);
    }
    
    studioButton.addEventListener(MouseEvent.CLICK, studio);
    function studio(event:MouseEvent):void {
    	var studioLoader:Loader = new Loader();
    	addChild(studioLoader);
    	var url:URLRequest = new URLRequest("studio.swf");
    	studioLoader.load(url);
    }
    
    faqButton.addEventListener(MouseEvent.CLICK, faq);
    function faq(event:MouseEvent):void {
    	var faqLoader:Loader = new Loader();
    	addChild(faqLoader);
    	var url:URLRequest = new URLRequest("faq.swf");
    	faqLoader.load(url);
    }
    The site is temporarily posted here MarkAC.com

    As you can see the "reelButton" loads a swf with video and audio.
    The problem is that the audio from the "reel" page continues to play when I load a new page.
    How would modify this code in order to implement the "unloadAndStop" function in AS3 so that when I click on the "studioButton" and the "faqButton" the sound which was loaded from the "reelButton" will unload and Stop?

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    12

    resolved Got it!

    Code:
    var contentLoader:Loader = new Loader();
    addChild(contentLoader);
    
    reelButton.addEventListener(MouseEvent.CLICK, reel);
    studioButton.addEventListener(MouseEvent.CLICK, studio);
    faqButton.addEventListener(MouseEvent.CLICK, faq);
    function reel(event:MouseEvent):void {
    	loadURL("reel.swf");
    }
    function studio(event:MouseEvent):void {
    	loadURL("studio.swf");
    }
    function faq(event:MouseEvent):void {
    	loadURL("faq.swf");
    }
    function loadURL(url:String):void {
    	contentLoader.unloadAndStop();
    	var request:URLRequest = new URLRequest(url);
    	contentLoader.load(request);
    }
    I also had to remember to set the publish settings to Flash Player 10

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Location
    NJ
    Posts
    138

    Talking

    You have no idea how much this one post has just helped me... I love you, man!
    Two wrongs don't make a right... but three lefts do.
    www.threelefts.com

  4. #4
    Junior Member
    Join Date
    Jan 2009
    Posts
    12

    I know!

    I looked all over for an answer to this problem. I posted on 4 different flash forums and then posted the answer on all 4 so the word should be out now.

  5. #5
    Junior Member
    Join Date
    Mar 2009
    Posts
    1
    Hi. Please please help me on this.

    I'm using very similar code to the code above and it works a treat for loading external swfs containing video....one thing though is that when my external swfs contain a preloader it seems to mess the whole thing up. I see in darkradio's site www.markac.com he has a preloader for each of the external swfs and it works fine. Can someone please tell me how that is done? Thank you.

    Here is the code i'm using for my preloader:
    stop();


    //Preloader Action Script
    loaderInfo.addEventListener (ProgressEvent.PROGRESS, plLoading);

    function plLoading(event:ProgressEvent) :void {
    var pcent:int=event.bytesLoaded/event.bytesTotal*100;
    //loadbar_mc is the name of the load bar movie clip instance
    loadbar_mc.scaleX=pcent/100;
    //percentDone_dtext is the name of the dynamic text box that
    //displays the percentage
    percentDone_dtext.text=String(pcent) + "%";
    if(pcent==100) {
    gotoAndPlay(2);
    }


    }
    and here's my code for the main swf's navigation:

    function gallery(event:MouseEvent):void {
    loadURL("pageGallery.swf");
    contentLoader.x = 50;
    contentLoader.y = 180;
    }

    function links(event:MouseEvent):void {
    loadURL("pageLinks.swf");
    contentLoader.x = 50;
    contentLoader.y = 180;
    }

    function contact(event:MouseEvent):void {
    loadURL("pageContact.swf");
    contentLoader.x = 50;
    contentLoader.y = 180;
    }

    function loadURL(url:String):void {
    contentLoader.unloadAndStop();
    var request:URLRequest = new URLRequest(url);
    contentLoader.load(request);
    }

    gallery_mc.addEventListener(MouseEvent.CLICK, gallery);
    links_mc.addEventListener(MouseEvent.CLICK, links);
    contact_mc.addEventListener(MouseEvent.CLICK, contact);

  6. #6
    Junior Member
    Join Date
    Feb 2009
    Posts
    10
    Thanks darkradio, that code works for me except for one part.

    The error I'm getting is:
    1061: Call to a possibly undefined method unloadAndStop through a reference with static type flash.display:Loader.
    When I change "unloadAndStop" to just "unload" I don't get any errors, however my videos will overlap. Why isn't unloadAndStop working?

    It feels like I'm missing something easy here, anyone got any ideas?
    Last edited by browntimmy; 04-26-2009 at 02:53 AM.

  7. #7
    Junior Member
    Join Date
    Feb 2009
    Posts
    10
    Nevermind, stupid mistake. I changed the publish settings to Flash Player 10 once but didn't save it and it went back to 9, I should have doublechecked before posting. Now it works.

  8. #8
    Lucky man

  9. #9
    Junior Member
    Join Date
    Sep 2009
    Posts
    1
    darkradio....thank you sooooo much. I've been searching for something like UnloadAndStop for 2 weeks now. Why is it so difficult to find this basic info??

    thanks!!!!

  10. #10
    Junior Member
    Join Date
    Feb 2010
    Posts
    12
    Hi darkRadio I've done your example but my loaded swf still there leaking my memory out, It is amazing, I've been dealing with this for a month, I've changed my CS to 4 in other to use the unloadAndStop method but nothing seem to work in order to totally remove from memory the loaded swf, even with your example the swf is stuck there.

    I've made and SWF for an example with an ADDED_TO_STAGE and REMOVE_FROM_STAGE listeners, plus a destroy function that destroy the listener and objects.

    This is the code on the swf that will be loaded.
    Code:
    addEventListener(Event.ADDED_TO_STAGE, addedHandler);
    addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
    
    var logo_mc:MovieClip = new LogoMc();
    
    function addedHandler(evt:Event):void
    {
    	removeEventListener(Event.ADDED_TO_STAGE, addedHandler);
    	initAnimation();
    }
    
    function removedHandler(evt:Event):void
    {
    	removeEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
    	//Here comes the destroy function
    	destroy();
    }
    
    function initAnimation():void
    {
    
    	addChild(logo_mc);
    	logo_mc.x = 100;
    	logo_mc.y = 200;
    	logo_mc.addEventListener(Event.ENTER_FRAME, logoMove);
    	
    }
    	
    function logoMove(evt:Event):void
    	{
    		logo_mc.x += 10;
    	}
    	
    function destroy():void
    {
    	logo_mc.removeEventListener(Event.ENTER_FRAME, logoMove);
    	logo_mc = null;
    }
    Well then I named this swf as "myTestSwf.swf", and in the main movie that will load this example I've applied your approach with an unload button.

    Code:
    var contentLoader:Loader = new Loader();
    addChild(contentLoader);
    
    loadButton_btn.addEventListener(MouseEvent.CLICK, loadMySwf, false, 0, true);
    unloadButton_btn.addEventListener(MouseEvent.CLICK, unLoadMySwf,false, 0, true);
    
    
    function loadMySwf(evt:MouseEvent):void
    {
    	loadURL("mySwfTest.swf");
    }
    
    function loadURL(url:String):void
    {
    	contentLoader.unloadAndStop();
    	var request:URLRequest = new URLRequest(url);
    	contentLoader.load(request);
    }
    
    
    function unLoadMySwf(evt:MouseEvent):void
    {
    	if(contentLoader.content)
    	{
    		contentLoader.unloadAndStop();
    	}
    }

    Event thou that this is the most simple example of a SWF with an destroy function, an unloadAndStop method and weak references, the F&$$&%$% swf still there , good grief!, what else can I do?, why this swf doesn’t get away?, why the GC doesn’t take care of it?.

    Sorry for the multiple question but really I’m totally frustrated with this memory leaking and I cannot find the solution.

    Thanks for any insight on this one.

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