+ Reply to Thread
Results 1 to 7 of 7

Unload swf

This is a discussion on Unload swf within the Actionscript 3.0 newbies forums, part of the Flash English category; Hi Flep, I have a pages_mc with several frames, with labels , home, about, contact, and so on, each frame ...

  1. #1
    Member Settled In jimbo is on a distinguished road
    Join Date
    Jul 2007
    Posts
    34
    Rep Power
    0

    Unload swf

    Hi Flep,
    I have a pages_mc with several frames, with labels , home, about, contact, and so on, each frame is one page of a site. On one frame I load a swf with your example code:

    preloader_mc.stop();
    preloader_mc.visible=false;

    var swf:String='Oils.swf';
    var richiesta:URLRequest=new URLRequest(swf);
    var loader:Loader=new Loader();

    loader.contentLoaderInfo.addEventListener(Event.OP EN,inizia);
    loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS,inCaricamento);
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,completato);
    loader.load(richiesta);

    function inizia(e:Event):void
    {
    preloader_mc.visible=true;
    preloader_mc.play();
    }

    function inCaricamento(e:ProgressEvent):void
    {
    var percentuale:uint=(e.bytesLoaded/e.bytesTotal)*100;
    preloader_mc.loader_txt.text=percentuale.toString( )+' %';
    }

    function completato(e:Event):void
    {
    preloader_mc.stop();
    preloader_mc.visible=false;
    addChild(loader);
    }

    It works wonderful, but, when I navigate back to another page (frame), the swf remains. What script would I add to the other frames to unload this swf when I navigate to another page?

  2. #2
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Re: Unload swf

    Hi

    Before of:
    Code:
    var swf:String='Oils.swf';
    var richiesta:URLRequest=new URLRequest(swf);
    var loader:Loader=new Loader();
    
    loader.contentLoaderInfo.addEventListener(Event.OP EN,inizia);
    loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS,inCaricamento);
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,completato);
    loader.load(richiesta);
    try to say:
    loader.unload();
    remove all listeners of loader and reload var swf:String...etc etc

  3. #3
    Member Settled In jimbo is on a distinguished road
    Join Date
    Jul 2007
    Posts
    34
    Rep Power
    0

    Re: Unload swf

    Thank you . . . that is the first as3 I am learning that is as easy as as2 . . . it is very logical and very simple to understand.

  4. #4
    Member Settled In jimbo is on a distinguished road
    Join Date
    Jul 2007
    Posts
    34
    Rep Power
    0

    Re: Unload swf

    Okay, I still have trouble. I need to unload Oils.swf when the page changes - first I put the unload logic in the buttons:

    home_btn.setLabel("Home");
    home_btn.addEventListener(MouseEvent.CLICK, homeBtnClicked);
    function homeBtnClicked(event:MouseEvent)
    {
    if (myPage == "oils")
    {
    //// unload Oils.swf ////
    loader.unload();
    loader.contentLoaderInfo.removeEventListener(Event .OPEN,inizia);
    loader.contentLoaderInfo.removeEventListener(Progr essEvent.PROGRESS,inCaricamento);
    loader.contentLoaderInfo.removeEventListener(Event .COMPLETE,completato);

    } ///// end unload Oils.swf
    if (myPage != "home") {
    myPage = "home";
    gotoAndPlay("pageTween");
    }
    trace ("Home Button Clicked");
    }

    But I get an error of: Access of undefined property loader when I compile.

    So I put the unload code on each page that is NOT the Oils page, so that when a person goes to another page, if they come from the oils page, it will unload, but then I get the error:
    Cannot access a property or method of a null object reference.
    at content_fla::_pageContainer_11/content_fla::frame1()

    How can I unload the Oils.swf after a visitor has clicked to the oils page, and then goes away?

  5. #5
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Re: Unload swf

    The problem is you are moving the FLA timeline and ...for example... if you say
    var loader:Loader;
    in first frame and you try to get it from frame 5, Flash when moves from frame to frame deletes the variables.
    In that case the var loader becomes local.
    You should not move the FLA timeline.

    Did you see this tut:
    How to create a site loading external SWF with Flash CS3

  6. #6
    Member Settled In jimbo is on a distinguished road
    Join Date
    Jul 2007
    Posts
    34
    Rep Power
    0

    Re: Unload swf

    ahhh, I lose my timeline now :(
    Well, I must learn. I have another syntax question. I notice that you have line breaks in the middle of statements - is this now allowed? We do not only have a line break after the ;

    sezioni_array=new Array('http://www.flepstudio.org/swf/sito_tutorial/sezioni/home.swf',
    'http://www.flepstudio.org/swf/sito_tutorial/sezioni/sezione1.swf',
    'http://www.flepstudio.org/swf/sito_tutorial/sezioni/sezione2.swf',
    'http://www.flepstudio.org/swf/sito_tutorial/sezioni/sezione3.swf',
    'http://www.flepstudio.org/swf/sito_tutorial/sezioni/sezione4.swf',
    'http://www.flepstudio.org/swf/sito_tutorial/sezioni/sezione5.swf');

  7. #7
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Re: Unload swf

    It is allowed cos i'm filling up an Array.

+ Reply to Thread

Similar Threads

  1. Aiuto unload swf
    By maurissimo22 in forum Flash Italiano
    Replies: 0
    Last Post: 09-02-10, 16:12
  2. Unload issue
    By manny79 in forum advanced Actionscript 3.0
    Replies: 3
    Last Post: 18-12-09, 09:58
  3. unload external swf
    By mdracula in forum HELP free utilities
    Replies: 3
    Last Post: 08-12-09, 05:15
  4. load unload swf
    By skill83 in forum Actionscript 3.0 base
    Replies: 0
    Last Post: 06-11-08, 09:11
  5. since there is no unLoad
    By laikarecords in forum Actionscript 3.0 newbies
    Replies: 1
    Last Post: 09-07-08, 18:18

Tags for this Thread

Bookmarks

Posting Permissions

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