How to load and unload Multiple External SWF

hello there,
i need help to figuring out how to load and also unload(removing) multiple external SWF.
so here is what i;m trying to do,
i want to load multiple external SWF and play it on my main SWF now i hove no problem with just loading multiple SWF and placing it in the display list .The problem came up when i tried removing those loaded SWF from the display list ,The problem exist because i have no way to refer to what i have loaded and placed on the display list,
i used a single loader instance to load all that external swf,
i do know that we have to remove all the event listener related to the external SWF that we want to remove and for this purpose i have crated a function called destroy which the main objective for this function is to remove all event listener inside the swf and also isolating all variable so it would be eligible for garbage collecting, here is what the code look like:
// Create this in every object you use
public function destroy():void
     // Remove event listeners
     // Remove anything in the display list
     // Clear the references to other objects, so it gets totally isolated
sorry it just a kind of pseudocode cause this function will customize with it's own property i did this just for the purpose of simplicity and easy understanding..,
so now back to main problem how should i solve this problem??
i tried used an arraf to save all the loaded swf
     the array is just used to save the what the loader is loading but the adding to display method is using
movieClipActAsContainer.addChild(e.target.content); //the event is from the Event.COMPLETE
but i have a hard time using that arrya back and matching it to the one i got from the display list.
please do help me,
any suggestion would be greatly appreciated,
and if can pleas show me a source code or pseudocode of what you're suggesting to me cause my english is not so fluent yet,
thanks before.

Hey EI,
I had done this kind of project recently and for loading and unloading different swfs. I had used loaders specific to that filename and for removing I had used a single movieclip instance name and on clicking that specific loader request name that needs to be removed will be requested from the specific function. As mentioned below
Loading SWF:
===============================
swfLoaderIndia.load(swfRequestIndia);//This will load the request
If you are inside a movieclip while requesting use below code
MovieClip(this.root).addChild(swfLoaderIndia);//This will load swf on stage
or else
Stage.addChild(swfLoaderIndia);
Unloading SWF
=====================================
If you are inside a movieclip while requesting use below code
MovieClip(this.root).removeChild(swfLoaderIndia);//This will unload swf on stage
or else
Stage.removeChild(swfLoaderIndia);
Above code will be in specific function which will be requested when the loading and unloading is required.
I hope this helps you in your project.
With Regards,
Sagar S. Ranpise

Similar Messages

  • Load and unload the external swf file using AS3(for window, IOS and android)

    For the external swf file loading, I use this code
    load2.addEventListener(MouseEvent.MOUSE_DOWN, newvid);
    function newvid(event:MouseEvent) {
              trace("you clicked me");
              var loadit = new Loader();
              addChild(loadit);
        var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
        loadit.load(new URLRequest("scene02.swf"), _lc);
    its working great but I don’t know how to unload the loaded swf files (looking: unload one by one and unload all)
    in AS2 we have
    on (release) {
              loadMovieNum("scene2.swf", 1);
              unloadMovieNum(2);
              unloadMovieNum(3);
    but i need in AS3

    Now I use this code and this time I got these compiler errors
    package {
                    import flash.display.SimpleButton;
                    import flash.display.MovieClip;
                    import flash.events.MouseEvent;
                    //import flash.display.URLRequest;
                    //import flash.display.Loader;
                    import flash.events.Event;
                    import flash.system.ApplicationDomain;
                    import flash.net.URLRequest;
                    import flash.system.LoaderContext;            
                                    public class load1 extends SimpleButton {
                                                    var loadit:Loader;              
                                                    public function load1() {
                                                                    this.addEventListener(MouseEvent.MOUSE_DOWN, loadfile);
                                                    private function loadfile(event:MouseEvent):void {
                                                                    trace("you clicked me");
                                                                    loadit = new Loader();
                                                                    this.parent.addChild(loadit);
                                                                    var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
                                                                    loadit.load(new URLRequest("s01.swf"), _lc);
                                                    private function unloadfile(event:MouseEvent):void {
                                                                    loadit.unloadAndStop();

  • How to load and unload more than one external swf files in different frames?

    I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
    I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
    Thanks

    Look into using the Loader class to load the swf files.  If you want to have it happen in different frames then you can put the code into the different frames.

  • How to load and display the external flv video files in dynamicly and the how to control the flv fil

    How to load and display the external flv video files in dynamicly using AS 3.0
    and  How to control the flv file  add the play paus button and add seekbar.
    I have using to load the flv file following code
    var flvPlaceHolder1:MovieClip = new MovieClip();
    var vid1:Video = new Video(734, 408);
    flvPlaceHolder1.addChild(vid1);
    addChild(flvPlaceHolder1);
    flvPlaceHolder1.x = 1059;
    flvPlaceHolder1.y = 152;
    var nc1:NetConnection = new NetConnection();
    nc1.connect(null);
    var ns1:NetStream = new NetStream(nc1);
    vid1.attachNetStream(ns1);
    var listener1:Object = new Object();
    listener1.onMetaData = function(evt:Object):void {};
    ns1.client = listener1;
    ns1.play("GV-1600 TURNING.flv");
    ns1.addEventListener(NetStatusEvent.NET_STATUS, statusChanged1);
    function statusChanged1(ns1:NetStatusEvent):void
             trace(ns1.info.code);
            if (ns1.info.code == 'NetStream.Buffer.Empty')
                 trace('the video has ended');
                 removeChild(flvPlaceHolder1);
                 //trace('removeChild');
                gotoAndPlay(1786);
    then how to add the play,paus ,full screen button    and   seekbar,volumebar.

    I have to Create the flash presentation for our company product
    In this presentation the left  side the text animation are displayed then right side the our product video is displayed.
    In this presentation i need the following option :
    1, The first product video and animation is finished then the next product is played
    2, then the video displayed  (size width and height 400x300) , I click this video to increase the size(ex:1000x700)
    3, then the playing video i control  it play, stop, paus button and volume bar, seek bar.
    4, then this presentation is displayed on 42 inches LCD TV so this full presentation is run full screen.
    I have finished first two steps 1 and 2
    the following are the screen short and code:-
    code :-
    var count=0;
    var flvPlaceHolder2:MovieClip = new MovieClip();   
    var vid2:Video = new Video(734, 408);
    flvPlaceHolder2.addChild(vid2);
    addChild(flvPlaceHolder2);
    flvPlaceHolder2.x = 1059;
    flvPlaceHolder2.y = 152;
    var nc2:NetConnection = new NetConnection();
    nc2.connect(null);
    var ns2:NetStream = new NetStream(nc2);
    vid2.attachNetStream(ns2);
    var listener2:Object = new Object();
    listener2.onMetaData = function(evt:Object):void {};
    ns2.client = listener2;
    ns2.play("GS-4000.flv");
    this.addEventListener(Event.ENTER_FRAME, BtnFadeIn2);
    function BtnFadeIn2(event:Event):void
        if (this.currentFrame == 387)
            /*flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            trace('Screen size is changed');*/
            if(count==0)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            count++;
    ns2.addEventListener(NetStatusEvent.NET_STATUS, statusChanged2);
    function statusChanged2(ns2:NetStatusEvent):void
        trace(ns2.info.code);
        if (ns2.info.code == 'NetStream.Buffer.Empty')
                trace('the video has ended');
                 removeChild(flvPlaceHolder2);
                 //trace('removeChild');
                gotoAndPlay(433);
    flvPlaceHolder2.buttonMode=true;
    flvPlaceHolder2.addEventListener(MouseEvent.CLICK,home2);
    function home2(e:MouseEvent):void
        if(vid2.width==734 && vid2.height==408)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
        else
            flvPlaceHolder2.x = 1059;
            flvPlaceHolder2.y = 152;
            vid2.width=734;
            vid2.height=408;

  • How to load and unload same SWF with different xmlFilePath?

    I have a slideshow on my homepage and try to load and unload same instance with different xmlFilePath based on language on the same page.
    var flashvars = {
            xmlFilePath: escape("http://www.bodto.com.tr/kik.aspx"),
            xmlFileType: "OPML",
            lang: swfobject.getQueryParamValue("lang")    
            //initialURL: escape(document.location)   
          var params = {
            bgcolor: "#000000",  
            allowfullscreen: "true",
            wmode:"transparent",
            allowScriptAccess: "always"
          var attributes = {}
              swfobject.embedSWF("/swf/slideshowpro.swf", "flashcontent", "550", "400", "10.0.0", false, flashvars, params, attributes);
    Actionscript3
    var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
    my_ssp.xmlFilePath = langPath;
    var fileType = root.LoaderInfo.parameters["xmlFileType"];
    my_ssp.xmlFileType = fileType;
    Based on above informations, how could I achieve it?

    Suddenly that code in the following gives me some error
    var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
    my_ssp.xmlFilePath = langPath;
    var fileType = root.LoaderInfo.parameters["xmlFileType"];
    my_ssp.xmlFileType = fileType;
    Access of possibly undefined property LoaderInfo through a reference with static type flash.display:DisplayObject.
    The only code snippet works is
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    for (var param in paramObj) {
       if (param == "xmlFilePath") {
          my_ssp.xmlFilePath = paramObj[param];
       if (param == "xmlFileType") {
          my_ssp.xmlFileType = paramObj[param];

  • How to load and unload external .swfs in a main .fla then load another external .swf on top

    I know that the question sounds confusing. I am new to AS3 but a little dangerous with it.
    The project
    I'm putting together a website tour with has a main .fla with navigation buttons. The navigation buttons load external .swfs using X and Y properties. Every external .swf houses a scrubber bar, play pause buttons which calls to a movie clip which houses the animation.
    The problem:
    Everything was working great, until someone mentioned "Hey, what if at the end of each loaded external .swf, a button appears that says "go to next section".
    So basically we are trying to give the user another way to get to the next section in the left hand navigation once the animation ends, in addition to being able to click in the left hand navigation for the next section. It's kind of like when a youTube video ends and it displays a button to go to the next movie that's in line, but you can also do it in the thumnail navigation as well.
    Ok, let's try it. Well, after many nights, searching the web and trying everything I am waving the white flag. I went through the lynda.com book over and over but I get an error message when I add code related to the parent timeline. I can actually get the next section to load on top of the previously loaded .swf, but it's buggy and I think the previous section is showing through underneath. Plus the scrubber isn't really working right. Since every .swf has a scrubber to control it, shouldn't it just load on top of the previous .swf? Do I need to add coding related to the parent timeline?
    I don't know if I should paste my code here, I have a sample .fla too. Help is so greatly appreciated!!!! If this can work, I think it would be very useful for anyone else doing something like this - I would definitely share any knowledge gained!
    Thanks.
    Jen

    If you want to utilize that code as a starting point (hopefully you understand what it does, and that the code actually works), then you need to modify it such that the array at the start has your filenames instead of the three it now shows, and the three buttons it uses are changed to the next and previous buttons you intend to use.  Here are the functions you need to make adjustments to...
    function onCompletePreloading():void {
            _loadedSWFs = 0;
            contentContainer.addChild(_swfClipsArr[_loadedSWFs]);
            next_btn.addEventListener(MouseEvent.CLICK, setContent);
            prev_btn.addEventListener(MouseEvent.CLICK, setContent);
    function setContent(event:MouseEvent):void {
            var _swfToAdd:MovieClip;
            if(event.currentTarget.name == "next_btn") {
                _loadedSWFs += 1;
                if(_loadedSWFs == _swfClipsArr.length){
                       _loadedSWFs = 0;
            } else if(event.currentTarget.name == "prev_btn"){
                _loadedSWFs -= 1;
                if(_loadedSWFs == -1){
                       _loadedSWFs = _swfClipsArr.length-1;
            _swfToAdd = _swfClipsArr[_loadedSWFs];
            contentContainer.removeChildAt(contentContainer.numChildren-1);
            contentContainer.addChild(_swfToAdd);
            trace(_swfToAdd.customID);

  • Load and consecutively play external swf's

    Hi,
    I have three external swf files - part1, part2 and part3. I
    know how to load one clip but I would like to know how to
    dynamically load them into an empty MC and then play them in full
    consecutively without any fancy transitions so that it plays like
    one big movie using Actionscript (no button triggers!).
    I have some very BASIC actionscript knowledge but am not sure
    which way is best. If someone could give me some "simple" step by
    step advise it would be grately apreciated.
    Danielle

    Ok I followed your instructions and when I play the main swf
    (I call - load_swfs) file it plays part1.swf fine but then it gets
    to the first frame of part2.swf (which is blank) and just stops and
    doesn't go any farther! Did I put something in the wrong place?
    I've written what I did and where below.
    // In my main file (load_swfs) it's just a single blank frame
    with this code in it :-
    tl=this;
    swfA=["part1.swf","part2.swf","part3.swf"];
    dep=0;
    numLoaded = 0;
    totalLoad=3;
    lo=new Object();
    lo.onLoadInit=function(target){
    numLoaded++;
    checkIfAllLoaded();
    function checkIfAllLoaded(){
    if(numLoaded==totalLoad){
    holder1.play();
    } else {
    mc=this.createEmptyMovieClip("holder"+(numLoaded+1),dep++);
    mcl.loadClip(swfA[numLoaded],mc);
    mcl=new MovieClipLoader();
    mcl.addListener(lo);
    mc=this.createEmptyMovieClip("holder"+(numLoaded+1),dep++);
    mcl.loadClip(swfA[numLoaded],mc);
    // In part1.swf in the last frame is :-
    tl.holder2.play();
    this.removeMovieClip();
    // In part2.swf frame 1 is blank with a stop(); and in the
    last frame is:-
    tl.holder3.play();
    this.removeMovieClip();
    // In part3.swf frame 1 is blank with a stop();
    Let me know where I went wrong!
    Thanks

  • Controlling multiple external swfs from main timeline

    Hi, I've been trying to combine the features of two tutorials I found, one that deals with controlling external swf's from the main timeline and the other that explains how to load and unload multiple external swf's.  I'd like to be able to load and unload multiple external swf's, and control these swf's buttons from the main timeline. 
    I asked this same question on the forum of the site where I found these tutorials, and receive only one reply saying that "it should'nt be hard to do." but they did not elaborate any further.  This left me think that I was missing something very obvious and I've spent too much time now trying to work what it is now.  I understand pretty much how both pieces of code work, but just can't work out how to combine them.
    If someone could explain it to me, I'd much appreciate it.
    Tutorial One code - controlling an external swf from the main timeline.
    var ldr:Loader = new Loader();
    var urlReq:URLRequest = new URLRequest("swfs/balls.swf");
    ldr.load(urlReq);
    function loadHandler (event:Event) {
    var myClip:MovieClip = event.target.content;
    addChild(myClip);
    function myClipOver(event:MouseEvent):void {
    myClip.myBlueBalls.stop();
    function myClipOut(event:MouseEvent):void {
    myClip.myBlueBalls.play();
    // set listeners
    myClip.addEventListener(MouseEvent.ROLL_OVER, myClipOver);
    myClip.addEventListener(MouseEvent.ROLL_OUT, myClipOut);
    // listener
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
    Tutorial Two code - loading and unloading multiple external swfs.
    var Xpos:Number = 110;
    var Ypos:Number = 180;
    var swf:MovieClip;
    var loader:Loader = new Loader();
    var defaultSWF:URLRequest = new URLRequest("swfs/eyesClosed.swf");
    loader.load(defaultSWF);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    // Btns Universal function
    function btnClick(event:MouseEvent):void {
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
        loader.y = Ypos;
    addChild(loader);
    // Btn listeners
    eyesClosed.addEventListener(MouseEvent.CLICK, btnClick);
    stingray.addEventListener(MouseEvent.CLICK, btnClick);
    demon.addEventListener(MouseEvent.CLICK, btnClick);
    strongman.addEventListener(MouseEvent.CLICK, btnClick);

    I will not be able to help you with whatever relaxatraja provided though it is purported by relaxatraja to be clearly explaining what I was explaining (???).
    Your loadHandler function appears a bit confused.  For the code you show I don't see you assigning any event listeners for the events that will be dispatched in the loaded file.  As I showed earlier, your loadHandler function should be assigning a listener for the event that will be dispatched (modified slightly below). and if you have three different events being dispatched in the loaded file, then you'll do better to have three different listeners.  I show only one below for one of the events you dispatch...
    function loadHandler (event:Event) {
      // assign a listener for the loaded file's goExit function's event
       MovieClip(event.currentTarget.content).addEventListener("close", event1Handler);
    // I can't make sense of what you have here
        removeChild(myClip); // why ?? - it hasn't been added yet as far as I can see - error 2007?
        var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf"); // the event.target is the Loader
        ldr.load(newSWFRequest); // this will load over the file you just finished loading??
        ldr.x = Xpos;
        ldr.y = Ypos;
        addChild(myClip);  // why?? it has nothing in it
    function event1Handler(e:Event):void {
        // do whatever is involved with what the "close" event is supposed to do
        trace("goExit function executed");
    As far as what you have in the loaded file, you appear to be trying to pass the files names as if they were parameters.  The file naming should be done at the receiving side for the event handler function for the event listener.  While you could create a custom event that include parameters that you can pass, that's another level of coding that is better left for a future experience.
    Study the following - understand it before you try to use it.
    Below is a link to some files I made for another posting that demonstrates what I have been explaining.  The neurope file is the main file.  Publish the netherlands file so that you have an swf to load for it, and then run the neurope file.  The file that gets loaded (netherlands) only has a button in it that when clicked dispatches an event for which the main file (neurope) has assigned a listener.  The main file displays a message when the button gets clicked in the loaded file.
    http://www.nedwebs.com/Flash/neurope.zip

  • Help with load and unload swf file.

    hello, just now i try, to  load my file using the code snippet 'load and unload' i manage to load the next file succesfully but why my recent file still appear in the background? how do i make it gone?

    When you load another SWF you're loading it 'inside' the current SWF but it appears that you want to replace the current SWF entirely with the new SWF, is that correct?
    If so you should make what's usually known as a 'stub' or a loader. Make an empty project that merely acts as a loader. It should load your first SWF and when you press a button on that first SWF to load a second SWF, it should signal the 'stub' it's loaded inside to unload the first SWF and then load the second.
    e.g. a stub.swf (just coding out of memory, not error checked, just to give a general idea):
    // make a new loader to do all the loading of SWFs
    var loader:Loader = new Loader();
    // and display
    addChild(loader);
    // a function to load a SWF into the loader (replacing any existing SWF)
    function loadSWF(path:String):void
         // assure path is defined or do nothing
         if (!path) return;
         // load requested SWF
         loader.load(new URLRequest(path));    
    // load initial SWF
    loadSWF('/path/to/1.swf');
    For your 1.swf to use the function, you're currently inside the .content property of a Loader so I believe you can just run a command like: Object(this.parent.parent).loadSWF('/path/to/2.swf');
    This example obviously lacks any error checking or transitions but you can add those and season to taste.

  • Display/load and Unload SWF in flex

    hi friends
    i wnat to disply external SWF file into flex but without using SWFLOader(it's make lot's of problem) nad i also Embed that SWF
    this is code
    [Embed(source="1.swf")]
    private var loadswf:Class;
    private function load():void{
    var symb:MovieClip = new loadswf() as MovieClip;
    this.addChild(symb);
    it's give me error....
    TypeError: Error #1034: Type Coercion failed: cannot convert demos_loadswf@39ab3c1 to mx.core.IUIComponent.
    please help to resolve this error or give me suggestion to simple Disply/Load and Unload Embed SWF file in flex

    thnx Flex harUI
    i added UI componentes now my full code is like..
            import mx.controls.Image;    
            import mx.controls.Alert;
            [Embed(source = "1.swf")]
            public var SWF:Class;
            [Embed(source = "2.swf")]
            public var SWF2:Class;
            private var mc:MovieClip;
            private var img:Image;
            protected function checkBtn_clickHandler(event:MouseEvent):void
                clear();
                img = new Image();
                img.width=Number("700");
                img.height=Number("700");
                mc = new MovieClip();
                mc = MovieClip(new SWF());
                img.source = mc;
                vBox0.addChild(img);
            protected function critcalBtn_clickHandler(event:MouseEvent):void
                clear();
                img = new Image();
                img.width=Number("700");
                img.height=Number("700");
                mc = new MovieClip();
                mc = MovieClip(new SWF2());
                img.source = mc;
                vBox0.addChild(img);
            protected function clear():void
                try{
                    if(mc!=null){
                        flash.media.SoundMixer.stopAll();
                        img.source="";
                        img.source=null;
                        mc=null;
                        vBox0.removeChild(DisplayObject(img));
                        vBox0.removeAllElements();
                        vBox0.removeAllChildren();
                }catch(e:Error){
                    Alert.show(e + " ----::---- ");
    <mx:Canvas id="vBox0" width="700" height="700" ></mx:Canvas>
    <mx:HBox >
            <mx:Button id="checkBtn" label="first" click="checkBtn_clickHandler(event)"/>
            <mx:Button id="critcalBtn" label="second" click="critcalBtn_clickHandler(event)"/>
    </mx:HBox>
    now my error gone!!! but one problem is there when i unload my first SWF and load second SWF(on button click), my first SWF sound are still play in Background, i cn't unstand Y this will happen coz i already remove all object and child from my Canvas.
    any help on this....

  • Unloading an External SWF

    Hi,
    I'm building a site that has 7 sections. 1 section is a Photo Gallery for which I'm loading an external SWF file that is controlled by an XML file. Im doing this for allowing content editing any time.
    All of the other content on the site is one-time, no backend required.
    I've successfully loaded the external swf file into a loader in one of the frames. However, when I navigate away to the other 6 sections, I'm unable to unload the external SWF loader. How do I go about this?
    Here's my code that loads the external SWF in one frame:
    import flash.events.MouseEvent;
    //This creates a new instance of the loader object.
    var my_Loader:Loader = new Loader();
    //This creates a new instance of the URLRequest object that contains the
    //path to the external SWF.
    var my_url:URLRequest=new URLRequest("gallery.swf");
    //These listeners detect when the file has finished loading, and if the
    //correct file is loaded.
    my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
    my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
    //The load method then loads the SWF file into the loader object.
    my_Loader.load(my_url);
    //This will offset the load SWF file, so be appear at (20, 20) on the stage.
    my_Loader.x = 37.85;
    my_Loader.y = 74.90;
    //This function adds the external SWF to the stage.
    function finishLoading(loadEvent:Event) {
    addChild(loadEvent.currentTarget.content);
    //This function displays a message if the file is not found.
    function errorHandler(errorEvent:Event):void {
    trace("file missing");
    stop();
    Here's the code I'm using for the site navigation buttons. I tried adding my_Loader.unload(); for all of the button Event listener functions. Its still not working.
    import flash.events.MouseEvent;
    vinaybtn.addEventListener(MouseEvent.CLICK, vinay);
    function vinay(event:MouseEvent):void
        my_Loader.unload();
        gotoAndStop(2);
    priyabtn.addEventListener(MouseEvent.CLICK, priya);
    function priya(event:MouseEvent):void
        gotoAndStop(3);
    gallerybtn.addEventListener(MouseEvent.CLICK, gallery);
    function gallery(event:MouseEvent):void
        gotoAndStop(4);
    bestwishesbtn.addEventListener(MouseEvent.CLICK, bestwishes);
    function bestwishes(event:MouseEvent):void
        my_Loader.unload();
        gotoAndStop(5);
    invitationbtn.addEventListener(MouseEvent.CLICK, invitation);
    function invitation(event:MouseEvent):void
        gotoAndStop(6);
    rsvpbtn.addEventListener(MouseEvent.CLICK, rsvp);
    function rsvp(event:MouseEvent):void
        gotoAndStop(7);
    Any help would be much appreciated.
    Thanks,
    Sudarshan

    try:
    var mc:MovieClip;
    //This function adds the external SWF to the stage.
    function finishLoading(loadEvent:Event) {
    mc=loadEvent.currentTarget.content as MovieClip;
    addChild(mc);
    vinaybtn.addEventListener(MouseEvent.CLICK, vinay);
    function vinay(event:MouseEvent):void
        removeChild(mc)
        gotoAndStop(2);

  • Best practices for using .load() and .unload() in regards to memory usage...

    Hi,
    I'm struggling to understand this, so I'm hoping someone can explain how to further enhance the functionality of my simple unload function, or maybe just point out some best practices in unloading external content.
    The scenario is that I'm loading and unloading external swfs into my movie(many, many times over) In order to load my external content, I am doing the following:
    Declare global loader:
    var assetLdr:Loader = new Loader();
    Load the content using this function:
    function loadAsset(evt:String):void{
    var assetName:String = evt;
    if (assetName != null){
      assetLdr = new Loader();
      var assetURL:String = assetName;
      var assetURLReq:URLRequest = new URLRequest(assetURL);
      assetLdr.load(assetURLReq);
      assetLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)
      assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
      function loaded(event:Event):void {
       var targetLoader:Loader = Loader(event.target.loader);
       assetWindow.addChild(targetLoader);
    Unload the content using this function:
    function unloadAsset(evt:Loader) {
    trace("UNLOADED!");
    evt.unload();
    Do the unload by calling the function via:
    unloadAsset(assetLdr)
    This all seems to work pretty well, but at the same time I am suspicious that the content is not truly unloaded, and some reminents of my previously loaded content is still consuming memory. Per my load and unload function, can anyone suggest any tips, tricks or pointers on what to add to my unload function to reallocate the consumed memory better than how I'm doing it right now, or how to make this function more efficient at clearing the memory?
    Thanks,
    ~Chipleh

    Since you use a single variable for loader, from GC standpoint the only thing you can add is unloadAndStop().
    Besides that, your code has several inefficiencies.
    First, you add listeners AFTER you call load() method. Given asynchronous character of loading process, especially on the web, you should always call load() AFTER all the listeners are added, otherwise you subject yourself to unpredictable results and bud that are difficult to find.
    Second, nested function are evil. Try to NEVER use nested functions. Nested functions may be easily the cause for memory management problems.
    Third, your should strive to name variables in a manner that your code is readable. For whatever reason you name functions parameters evt although a better way to would be to name them to have something that is  descriptive of a parameter.
    And, please, when you post the code, indent it so that other people have easier time to go through it.
    With that said, your code should look something like that:
    function loadAsset(assetName:String):void{
         if (assetName) {
              assetLdr = new Loader();
              assetLdr.contentLoaderInfo.addEventListener(Event.INIT , loaded);
              assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
              // load() method MUST BE CALLED AFTER listeners are added
              assetLdr.load(new URLRequest(assetURL));
    // function should be outside of other function.
    function loaded(e:Event):void {
         var targetLoader:Loader = Loader(event.target.loader);
         assetWindow.addChild(targetLoader);
    function unloadAsset(loader:Loader) {
         trace("UNLOADED!");
         loader.unload();
         loader.unloadAndStop();

  • Profiling the loading and unloading of modules

    Modules appear to be the ideal solution for building complex rich internet applications but first hand experience has also shown me that they can leak memory like nothing else. I've read anything and everything I could find about modules and module loading/unloading including of Alex Harui's blog post "What We Know About Unloading Modules" that reveals a number of potential leak causes that should be considered.
    I've now created a simple soak test that repeatedly loads and unloads a specified module to help identify memory leaks using the profiler. However, even with the most basic of modules, I find that memory usage will steadily grow. What I'd like to know is what memory stuff is unavoidable flex overhead associated with the loading of modules and what memory stuff am I guilty for, for not cleaning up object references? I'd like to be able to establish some baseline values to which I will be able to compare future modules against.
    I've been following the approach suggested in the Adobe Flash Builder 4 Reference page "Identifying problem areas"
    "One approach to identifying a memory leak is to first find a discrete set of steps that you can do over and over again with your application, where memory usage continues to grow. It is important to do that set of steps at least once in your application before taking the initial memory snapshot so that any cached objects or other instances are included in that snapshot."
    Obviously my set of discrete steps is the loading and unloading of a module. I load and unload the module once before taking a memory snapshot. Then I run my test that loads and unloads the module a large number of times and then take another snapshot.
    After running my test on a very basic module for 200 cycles I make the following observations in the profiler:
    Live Objects:
    Class
    Package (Filtered)
    Cumulative Instances
    Instances
    Cumulative Memory
    Memory
    _basicModule_mx_core_FlexModuleFactory
    201 (1.77%)
    201 (85.17%)
    111756 (24.35%)
    111756 (95.35%)
    What ever that _basicModule_mx_core_FlexModuleFactory class is, it's 201 instances end up accounting for over 95% of the memory in "Live Objects".
    Loitering Objects:
    Class
    Package
    Instances
    Memory
    Class
    600 (9.08%)
    2743074 (85.23%)
    _basicModule_mx_core_FlexModuleFactory
    200 (3.03%)
    111200 (3.45%)
    However this data suggests that the _basicModule_mx_core_FlexModuleFactory class is the least of my worries, only accounting for 3.45% of the total memory in "Loitering Objects". Compare that to the Class class with it's 600 instances consuming over 85% of the memory. Exploring the Class class deeper appears to show them all to be the [newclass] internal player actions.
    Allocation Trace:
    Method
    Package (Filtered)
    Cumulative Instances
    Self Instances
    Cumulative Memory
    Self Memory
    [newclass]
    1200 (1.39%)
    1200 (14.82%)
    2762274 (13.64%)
    2762274 (62.76%)
    This appears to confirm the observations from the "Loitering Objects" table, but do I have any influence over the internal player actions?
    So this brings me back to my original question:
    What memory stuff is unavoidable flex overhead associated with the loading of modules and what memory stuff am I guilty for, for not cleaning up object references? If these are the results for such a basic module, what can I really expect for a much more complex module? How can I make better sense of the profile data?
    This is my basic module soak tester (sorry about the code dump but there's not that much code really):
    basicModule.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/halo"
               layout="absolute" width="400" height="300"
               backgroundColor="#0096FF" backgroundAlpha="0.2">
         <s:Label x="165" y="135" text="basicModule" fontSize="20" fontWeight="bold"/>
    </mx:Module>
    moduleSoakTester.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/halo"
                   width="400" height="300" backgroundColor="#D4D4D4"
                   initialize="application_initializeHandler(event)">
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   import mx.events.ModuleEvent;
                   [Bindable]
                   public var loadCount:int = -1;
                   [Bindable]
                   public var unloadCount:int = -1;
                   public var maxCycles:int = 200;
                   public var loadTimer:Timer = new Timer(500, 1);
                   public var unloadTimer:Timer = new Timer(500, 1);
                   protected function application_initializeHandler(event:FlexEvent):void
                        loadTimer.addEventListener(TimerEvent.TIMER_COMPLETE, loadTimer_timerCompleteHandler);
                        unloadTimer.addEventListener(TimerEvent.TIMER_COMPLETE, unloadTimer_timerCompleteHandler);
                   protected function loadModule():void
                        if(loadCount < maxCycles)
                             moduleLoader.url = [correctPath] + "/basicModule.swf";
                             moduleLoader.loadModule();
                             loadCount++;
                   protected function unloadModule():void
                        moduleLoader.unloadModule();
                        unloadCount++;
                   protected function load_clickHandler(event:MouseEvent):void
                        load.enabled = false;
                        loadModule();
                        unload.enabled = true;
                   protected function unload_clickHandler(event:MouseEvent):void
                        unload.enabled = false;
                        unloadModule();
                        run.enabled = true;
                   protected function run_clickHandler(event:MouseEvent):void
                        run.enabled = false;
                        moduleLoader.addEventListener(ModuleEvent.READY, moduleLoader_readyHandler);
                        moduleLoader.addEventListener(ModuleEvent.UNLOAD, moduleLoader_unloadHandler);
                        loadTimer.start();
                   protected function moduleLoader_readyHandler(event:ModuleEvent):void
                        unloadTimer.start();
                   protected function moduleLoader_unloadHandler(event:ModuleEvent):void
                        loadTimer.start();
                   protected function loadTimer_timerCompleteHandler(event:TimerEvent):void
                        loadModule();
                   protected function unloadTimer_timerCompleteHandler(event:TimerEvent):void
                        unloadModule();
              ]]>
         </fx:Script>
         <mx:ModuleLoader id="moduleLoader"/>
         <s:VGroup x="20" y="20">
              <s:HGroup>
                   <s:Button id="load" label="Load" click="load_clickHandler(event)" enabled="true"/>
                   <s:Button id="unload" label="Unload" click="unload_clickHandler(event)" enabled="false"/>
                   <s:Button id="run" label="Run" click="run_clickHandler(event)" enabled="false"/>
              </s:HGroup>
              <s:Label text="loaded: {loadCount.toString()}" fontSize="15"/>
              <s:Label text="unloaded: {unloadCount.toString()}" fontSize="15" x="484" y="472"/>
         </s:VGroup>
    </s:Application>
    Cheers,
    -Damon

    Easiest way I've found to get your SDK version from within Builder is to add this: <mx:Label text="{mx_internal::VERSION}" />
    http://blog.flexexamples.com/2008/10/29/determining-your-flex-sdk-version-number/
    Peter

  • Trying to properly code a menu with buttons that can go back and forth between external swf files

    I have a project I've been working on that, when properly coded, has a "main menu" with 4 "doors" (buttons). When the corresponding buttons to these "doors" are clicked, it should go to and play an external .swf file. If that doesn't make sense, think of a DVD menu. You click play movie, it plays the movie. When the movie is over, there's two buttons on that swf file to either play the movie over or go back the main menu, which is an external .swf file (Remember, we go to the movie from the menu, which is a seperate file). So far, the buttons work. The menu works. However, from the movie, at the conclusion, when I click the button to go back to the main menu, it displays the movie clip and the buttons, but none of the buttons work. I'm starting to think it has to do with the fact the main menu was written in AS3 and the movie was made in AS2. If anyone can assist me in being to able to keep both files and still navigate between the two, being able to bring up the menu from the movie and be able to play the movie again, and so on and so on, that'd be GREAT. I'm somewhat of a noob to Flash, but I learn quickly and I'm open to any suggestions. Here's the code for main menu, which I guess acts as the parent file, and the movie. If I get this to work, I essentially would duplicate the same actions for the other 4 doors, once I complete the environments for them. Thanks
    Main.Fla/Swf (written in AS3)
    (This is the action on the first frame, that has all the buttons. For this question, I'm just trying to properly code for 'Door4', which is the "door" to the movie.)
    import flash.display.Loader;
    stop();
    var myLoader1:Loader=new Loader ();
    Door4.addEventListener(MouseEvent.CLICK, jayzSwf);
    function jayzSwf(myevent1:MouseEvent):void
              var myURL1:URLRequest = new URLRequest("jayzspeaks.swf");
              myLoader1.load(myURL1);
              addChild(myLoader1);
              myLoader1.x = 0;
              myLoader1.y = 0;
    Movie.Fla/Swf (written in AS2)
    (This is action on the button that returns to the menu)
    on (release) {
              this.createEmptyMovieClip("container",this.getNextHighestDepth());
              container.loadMovie("main.swf");

    At least you're going in the correct (mis)direction. You have AS3 loading AS2. So that's not a huge hurdle.
    I believe all you really need to do is send your Main.swf a signal that the content it loaded (e.g. jayzspeaks.swf) is done and you want to get rid of it.
    The code I pointed you to asks you to (upon download and import then) instantiate it in both AS2 and AS3. They give a very simple easy to understand line of code.
    // as2, load this in jayzspeaks.swf
    var myBridge:SWFBridgeAS2 = new SWFBridgeAS2("connectionID", clientObj);
    // as3, load this in main.swf
    var myBridge:SWFBridgeAS3 = new SWFBridgeAS3("connectionID", clientObj);
    Make sure the connectionID matches between them. Set it to whatever you want.
    When you're done with your as2 loaded content you'd send a signal (over localconnection) back to the AS3 Main like they say:
    myBridge.send("someFunctionToUnloadContent");
    myBridge.close();
    You'd need to make the as3 function "someFunctionToUnloadContent()" (example purposes only name) and it should unload the jayzspeaks.swf that was loaded in the loader.
    Make sure you get that close in there so you don't drill up a bunch of localconnection objects just like the simple source code says.

  • Can we load and unload the files in the run time?

    Can we load and unload the files in the run time?
    For example there are four files named "test1.h & test1.c" and another set "test2.h & test2.c" (I attached them as attachment to this post).
    test1.h contains code:
    int variable; //variable declared as integer
    test1.c contains code:
    variable = 1; //variable assigned a value
    test1.h contains code:
    char *variable; //variable declared as string
    test1.c contains code:
    variable = "EXAMPLE"; //variable assigned a string
    So here, in this case can I dynamically load / unload the first & second group of files so that the same variable name "variable" can be used both as integer and string? And if yes, how is that to be done?
    Solved!
    Go to Solution.
    Attachments:
    test.zip ‏1 KB

    What do you mean by "dynamically"?
    If you want to have a variable that either is an int or a char in the same program run, I'm afraid your only option is to define it as a variant and assign from time to time the proper data type in the variant according to some condition. Next, every time you access the variable you must firstly check which data type is stored in it, next access it in the proper way.
    If on the other hand your option or to have a run in which the variable is an int, next you stop the program and in a following run it is a char, you may have it by using some appropriade preprocessor clause:
    #ifdef  CHAR_TYPE
    #include "test1.h";        // variable defined as a char
    #else
    #include "test2.h";        // variable defined as int
    #endif
    Next, every time you want to access the variable you must proceed in the same vay:
    #ifdef  CHAR_TYPE
      variable = "string";
    #else
      variable = 1;
    #endif
    Does it worth the effort?
    Additionally, keep in mind that this "dynamical" approach can work only in the IDE, where you can properly #define your CHAR_TYPE or not depending on your wishes: when you compile the program, it will have only one #include depending on the definition of the macro.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

Maybe you are looking for

  • Remote VPN logIn using Mac

    I was looking for a software package for my MacBook Pro capable of remotely logging into a Windows XP system (place of work)to check email and access to server directories while traveling. I'm the one step child (artist) in the org with a Mac and the

  • Firefox won't open any website and displays an Invalid URL at all websites.

    Until now, I had no trouble with Firefox but everytime the new Firefox updated, everything came up as Invalid URL. For about a week I realised I could 'restore previous versions' of the file every day but now that isn't an option and I cannot access

  • Big Issue With Safari! Help!

    Hello, I have a Toshiba laptop with Windows Vista and I decided to download apple safari web browser but I am having a big issue, every time I open Safari it pop up a window saying ''Safari has stopped working, windows will find a solution for the pr

  • Goto functionality (query to query)

    Hello, I created two queries. With transaction "rsbbs" I refer one query as sender-query and the other as receiver-query. If I execute sender-query, for most of characteristics the functionality "Goto" works fine. That means data will display in rece

  • Can I backup multiple iphones on itunes

    I need to back up my boyfriend's old iphone 4 so his old stuff can be on his new iphone 5. I already have all of my own information backed up on my computer from my iphone 5. Can I do this with his on my computer withouth mixing up any information? T