Stage Resizing on "Clicked" External SWFs

Hello everyone!
Thanks for checking this out.
This has been bugging me for almost a week now. I hope I may find some assistance here. I've Googled for this and everytime I encounter an article with the solution and people saying it worked great for them, I thought it's going to help me too, but didn't. I'm pretty sure I did exactly what was instructed but mine is just weird.
I hope you can try to look at my files and see what's wrong, anyway this is just a simulation of my real project (which has the same problem) at a very small scale so it should be very easy to look at. I believe it's so easy to solve but I just couldn't nail it. Here's a brief description:
There's this main.swf that loads two external swfs in a UILoader upon click of the corresponding button. By the way, the code inside the external swfs listens for a stage resize... So, when user clicks on button 1 (named "LOAD 1"), it loads "content1.swf". User decides to resize the window, and layout resizes accordingly (in this case, they all center horizontally). User clicks on button 2 (named "LOAD 2"), it loads "content2.swf". Everything looks fine, apparently. But when user tries to resize the window again, an error pops up in the Output panel...
Honestly, I've built a new one here at my desktop using var loader:Loader = new Loader(); concept instead of the UILoader Flash component but still no luck. Please, hear me out. I don't think I want to give up.
Thanks!

Try this:
Rename setComp() and resizeComp() in content1 to setComp1() and resizeComp1()
Rename setComp() and resizeComp() in content2 to setComp2() and resizeComp2()
Now try resizing and you'll see the error being thrown with the new function names.
I think your problem deals with unloading your content. You should maybe try to properly unload content1 before loading content2 and vs. versa and see if that fixes your problem. I suspect that the resizeComp2 is still trying to resize an object that doesn't exist on the stage anymore, but the function is still loaded into memory and running. Unloading your swfs might clear this up.

Similar Messages

  • External SWF Disappears on Browser resize

    I am loading external swf's inside content_2 and when i resize my browser the external content OR content_2 disappears. Can someone help me as to what I need to do to stop this. I've tried adding an onresize function but that does not work. Here my as3 code:
    scroll_sb2.scrolling("content_2", "area_2", 0.18); // Range from 0.00 to 1.00
    stage.addEventListener(Event.RESIZE, resizeHandler);
    function resizeHandler(e:Event):void
    scroll_sb2.x = stage.stageWidth - scroll_sb2.width - 2;
    scroll_sb2.y = 0;
    scroll_sb2.height = stage.stageHeight;
    area_2.x = stage.stageWidth/2 - area_2.width/2;
    area_2.y = stage.stageHeight/2 - area_2.height/2;
    area_2.y = 0;
    area_2.height = stage.stageHeight;
    content_2.x = stage.stageWidth/2 - content_2.width/2;
    content_2.y = stage.stageHeight - content_2.height;  // comment this line if you whant to remove the carrusel affect on resize browser
    backgroundMC.x=0;
    backgroundMC.y=0;
    backgroundMC.width=stage.stageWidth;
    backgroundMC.height=stage.stageHeight;
    downbg_mc.x = 0;
    downbg_mc.y = 0;
    downbg_mc.width = stage.stageWidth;
    stage.align = StageAlign.TOP_LEFT;     
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.dispatchEvent(new Event(Event.RESIZE));
    var mem:String = Number ( System.totalMemory / 2048 / 2048 ).toFixed ( 2 ) + 'Mb';
    trace ( mem ); 

    Guys can you PLZZZ Help me out with this. I've been researching this ALL day with no solution, I'v
    e posted this in THREE forums and I havent gotten ONE response. Plz assist me!
    ALSO..This is the action script that's in my scrollbar movie:
    var sd:Number;
    var sr:Number;
    var cd:Number;
    var cr:Number;
    var new_y:Number;
    var drag_area:Rectangle;
    var scroll_content:MovieClip;
    var scroll_content_area:MovieClip;
    var scrolling_speed:Number; // 0.00 to 1.00
    //.............. SCROLL BUTTON .............//
    scroll_scroller.buttonMode = true;
    addEventListener ( MouseEvent.MOUSE_OVER, mouse_over );
    addEventListener ( MouseEvent.MOUSE_OUT, mouse_out );
    function mouse_over ( event:MouseEvent ) {
      scroll_scroller.alpha = 0.7;
    function mouse_out ( event:MouseEvent ) {
      scroll_scroller.alpha = 1;
    //.............. END scroll button...........//
    function scrolling( ct:String, ct_area:String, speed:Number ):void
    scrolling_speed = speed;
    if( scrolling_speed < 0 || scrolling_speed > 1 ) scrolling_speed = 0.50;
    scroll_content = parent[ct];
    scroll_content_area = parent[ct_area];
    scroll_content.mask = scroll_content_area;
    scroll_content.x = scroll_content_area.x;
    scroll_content.y = scroll_content_area.y;
    scroll_scroller.x = scroll_scrollable_area.x;
    scroll_scroller.y = scroll_scrollable_area.y;
    sr = scroll_content_area.height / scroll_content.height;
    scroll_scroller.height = scroll_scrollable_area.height * sr;
    sd = scroll_scrollable_area.height - scroll_scroller.height;
    cd = scroll_content.height - scroll_content_area.height;
    cr = cd / sd * 1.01;
    drag_area = new Rectangle( 0, 0, 0,scroll_scrollable_area.height -  scroll_scroller.height );
    if ( scroll_content.height <= scroll_content_area.height )
      scroll_scroller.visible = scroll_scrollable_area.visible = false;
    scroll_scroller.addEventListener( MouseEvent.MOUSE_DOWN, scroller_drag );
    scroll_scroller.addEventListener( MouseEvent.MOUSE_UP, scroller_drop );
    this.addEventListener( Event.ENTER_FRAME, on_scroll );
    function scroller_drag( me:MouseEvent ):void
    me.target.startDrag(false, drag_area);
    stage.addEventListener(MouseEvent.MOUSE_UP, up);
    function scroller_drop( me:MouseEvent ):void
    me.target.stopDrag();
    stage.removeEventListener(MouseEvent.MOUSE_UP, up);
    function up( me:MouseEvent ):void
    scroll_scroller.stopDrag();
    function on_scroll( e:Event ):void
    new_y = scroll_content_area.y + scroll_scrollable_area.y * cr - scroll_scroller.y  * cr;
    scroll_content.y += ( new_y - scroll_content.y ) * scrolling_speed;
    // END

  • External SWF using stage width & height...

    Hi,
    I have an external .swf file (zoomify-esque) that I would like to use in my Flex app, but it's size attributes use the stage width and height.
    This basically means that the loaded swf file will load at 100% of the size of the stage. I can resize the loaded .swf using whatever Flex component I put it in, but that shrinks it rather than behaving like it would if I embedded it in an HTML page.
    I hope that makes sense. If anyone could help me out with this, I'd be very grateful!
    Thanks in advance,
      Alex.

    Thanks for your response Alex,
    The swf is from an external company that we pay for virtual slide serving software, and I am currently unaware of any other zooming tools that can efficiently view medical images averaging over 5 gigapixels in size. If you know of any, that'd be really useful, but correctly embedding the original swf is preferred.
      Alex.

  • Loading external swf / resizing

    Hi,
    I'm loading external swf into my main project for sub sections to keep size down.  My main project is 1280 x 700px in size.
    In those sub-section I have some content with a scroller.
    When I load the swf and check the size its ok. But as soon as the scrollbars is initialized scroll bar is initialized the size of the external includes the text that goes off-stage for the sroller.
    I can resize it propotionaly when after its loader because i have the correct values. But if the user resizes his browser I get the wrong values and my resize code doesnt work because it's height is now incorrect.
    So is there a way to not include the off-stage elements to count as the height ?

    either hard-code that loaded swf's stage size or use code to determine that size in a frame before any off-stage content is added.

  • Dispatching Events - External SWF & Main Stage

    Hi Everyone
    I am dispatching two different events showbutton and removebutton from the code inside the LOADED SWF.
    on main file, (the one that is loading the swf file) i m listening for events and either showing or removing the
    buttons based on proper scenario. Here is he error i m getting. I appreciate if someone can help me understand
    the problem thanks.
    ERROR   1180  Call to a possibly undefined Method Event   - - - > dispatchEvent(new Event("showbutton"));
    -----------------EXTERNAL SWF -----------------
    dispatchEvent(new Event("removebutton"));
    dispatchEvent(new Event("showbutton"));
    -----------------MAIN STAGE-----------------------
    movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler)
    function loaderCompleteHandler(event:Event) {
        (event.currentTarget.content as MovieClip).addEventListener("removebutton", categoryClickHandler);
        (event.currentTarget.content as MovieClip).addEventListener("showbutton", categoryClickHandler2);
    function categoryClickHandler(event:Event):void {
        alaarm.visible=false
    function categoryClickHandler2(event:Event):void {
        alaarm.visible=true
        trace("yohoo");

    MathAdor,
    Have you considered solutions that don't involve event handlers available to AS3.
    If I understand correctly you are trying to:
    1.  Control buttons that exist in your main .swf file
    2.  Control the visibility of those buttons from a child .swf called into existence from the main .swf file
    You could control this completely from the child .swf by setting a variable for your parent .swf
    In your child .swf creat a variable that contains the parent movieclip:
    var myParentClip:MovieClip = MovieClip(parent.parent);
    Now control your buttons with the appropriate command from your child
    myParentClip.buttonName.visible = true;
    myParentClip.buttonName.visible = false;
    Total control from your child .swf
    Hope this helps

  • Component Loader resizing external swfs

    Hi. Fairly new to Flash. I'm putting together my first full
    Flash site. The tutorial I'm following along with for some
    assistance is written for Flash8, but I'm using CS3. To try to
    minimize differences, I'm doing my files in Actionscript 2.
    I've used an instance of the component Loader to load
    external swfs (my pages) into the content portion of my main swf.
    The problem I've run into is the loaded swfs are showing up at
    different sizes. For ease of layout, the document sizes of the
    external swfs are exactly the same as the mx.controls.Loader
    instance on my main swf. But when they load, one is coming in
    slightly larger than the original size, one nearly a quarter of the
    size it should be. Everything else works.
    In playing around to try to troubleshoot, I made one change
    to my home swf (the external that loads immediately with a
    Loader.contentPath command. This one had been loading slightly
    enlarged), I changed a guide layer so it was a regular layer, no
    longer a guide, then it loaded at the right size. When I changed
    the layer back to a guide, it loaded somewhat enlarged again. I
    tried turning off the guide layer on the other swf that was loading
    small, it didn't help. I'm going nuts trying to figure it out.
    I thought maybe it might have to do with the fact that some
    elements start outside the document frame of the external swfs and
    slide in, so I masked all layers to the size of the document. That
    didn't help. Is there some scale setting for the Loader component
    that I'm not aware of? That would cause the external swf to scale
    up or down to fit the size of the Loader instance?
    Any help would be appreciated. Thanks

    Thanks. I tried a few more searches in Flash's Help for
    Loader scaling and resize and found the scaleContent property, was
    just coming back here to say nevermind and saw your response.
    Sometimes it takes writing out the problem to spark more
    troubleshooting inspiration.
    BTW, changing Loader.scaleContent to false did solve my
    problem. :)

  • External SWF gets resized

    I'm using the code below in a movieclip in Flash CS3 to
    import an external swf into my project. However, every time I
    upload the site to the server (
    http://www.kimandbrett.com),
    when I click on Gallery, the Gallery.swf is stretched out & the
    image is too big. I tried uploading the same exact thing to
    http://www.personal.kent.edu/~nglase/FlashSite/index.html
    & it works just fine. The site that is not working is hosted by
    GoDaddy. Are there any server settings that might be causing it to
    behave differently?
    Thanks,
    Natalie

    stage.StageScaleMode.NO_SCALE;
    /* put this line in all your code */
    The entire Flash application is fixed, so that it remains
    unchanged even as the size of the player window changes. Cropping
    might occur if the player window is smaller than the content.

  • Open external swf from within another external swf?

    Hello, I'm relatively new to AS3 and have a problem that I'd like to see if anyone can provide a response.
    I have an external swf that is opened through a web page, but the swf does not diplay in a web page, we use javascript to remove the browser, control the window size to 1024X710, no scrollbars, etc. Within that external swf I want to use a button that the user can click to open a separate external swf that is located in the same folder; however, I want it to display as the original swf (without it being displayed in an Internet browser, no scroll bars, a certain size 1024X710), etc. I've been able to find script where you can open an external web page with a certain size window; however, I find nothing regarding how to open an external swf with conditions.
    Any help you can provide would be greatly appreciated!
    We use this script on a web page to open the external swf:
    <script language="Javascript">
      function openSWF1(cbtFile)
        window.open(cbtFile,"NewWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,widt h=1024,height=710");
    </script>
    We use the following html code to call the JS and open the applicable swf file:
    <a href="javascript:openSWF1('CBT/AppTrng/EIP-New-Siebel.swf')">Enterprise Image Processing (EIP)</a>

    Hi,
    I found this function and it works correctly; however, it seems to automatically move the movie to the next frame instead of staying on the same frame in which the function is displayed.
    The first function is to move to the next frame when the user presses the Tab key on their keyboard.
    stage.addEventListener(KeyboardEvent.KEY_DOWN, cool);
    function cool(e:KeyboardEvent):void {
          if(e.keyCode == Keyboard.TAB){
               gotoAndPlay("7");
    This function is to open an external swf in a sizeable window with no Internet window - it works great! However, it automatically navigates the parent movie clip to frame #7. What am I doing wrong?
    query_btn.addEventListener(MouseEvent.CLICK, MYBUTTON_link8);
    function MYBUTTON_link8(e:MouseEvent):void
        //navigateToURL(new URLRequest("icb.swf"), "_blank", "scrollbars=no,titlebar=no,toolbar=no,menubar=no,resizable=yes,width=1024,height=710");
    var gameURL:String = "http://opstraining.bcbsfl.com/NonPMI/RBMS/icb.swf";
    var jscommand:String = "window.open('"+gameURL+"','win','width=1024,height=710,toolbar=no,scrollbars=no,location =no,status=no,menubar=no');";
    var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
    navigateToURL(url, "_self");

  • How can I get a preloader to launch a main (external) swf file, and have the main file remove the preloader once it's fully loaded?

    Using Flash MX, ActionScript 2:
    I’ve been struggling for several weeks, trying to get a preloader to work on a large (~80 MB) photo portfolio file (using the method where the preloader is on frame 1 of the file, and when loading is completed, it jumps to the content).  I’ve done countless tutorials, and none seem to work on my presentation.  I even tried downloading a trial version of CS4 so I could export every one of the file’s library movie clips and images so that they load on Frame 2 (a feature MX doesn’t have).  It takes about 20 seconds for the .exe to load from a CD, and no matter which preloader construction I use, it always seems to appear in the last few seconds before the movie loads completely.  During the initial wait time, there’s no indication that anything is happening:  no hourglass on the mouse, and not even a blank screen. This is only true for the first time that the file is loaded from the CD; on subsequent loads, the file must already be in RAM, because it loads within a few seconds. 
    I decided that I’m going to try and make the file which the user clicks on (one named Windows_Portfolio.exe or another called Mac_Portfolio.hqx) the preloader so that it would be tiny, and would load instantly.  I want that file to launch the external huge portfolio file (renamed files.swf), keep track of its loading progress, and cycle through a slideshow (10 thumbnail images that transition into each other over 100 frames) proportionally, based upon the percentage of files.swf that had been loaded.
    I assume that there should be a loadMovie() or a loadMovieNum() command on the preloader’s timeline to launch files.swf, and that the initial code of files.swf should have some sort of this._parent._visible=false or other way of deleting the preloader on level0.  Can anyone explain the steps to me, or direct me to a good Flash MX tutorial that explains how to launch another external swf from a preloader .exe, keep track of its load progress, and delete the preloader .exe once the external swf had been loaded?
    Also, I’ve read that, using this construction on a CD, every file has to be in the same place, and that I can’t nest files.swf in a folder named “files,” and reference it with files/files.swf.  Is this true?
    Thanks for any assistance you can offer.

    If you know JavaScript (ECMA Script) then you might be able to get it done applying a for loop and a random function
    to the for loop if you know how to get a page-loaded request into JavaScript.
    But an easier solution, if you know ActionScript 3.0, and if your SWF's don't need to be recoded and can load into a "container" SWF would be to create a master FLA file that loads your SWF's in a random fashion using Math.random() as a multiplier, though you won't see much variation if you only have 2-3 SWF's to load--if you had more than that then you would begin to benefit from the random function's capabilities.  In ActionScript 3.0 use the load() method along with addChild() to load the SWF and add it to the stage.  You will be able to search for specifics on how to code the FLA properly by using Flash's Adobe Help tool and also using an internet search.
    -markerline
    P.S. Once you have the master FLA coded you can Publish it to an SWF and an HTML and if the container/master SWF needs to be in a page with other content you can simply copy and paste the object and embed tags for the container SWF from the published HTML into any place on your master HTML that you need it to reside.  You can then use CSS to control placement of the SWF object if it is in a div tag.

  • How can I load an external SWF into a movie clip that's inside other movie clip?

    Hi.
    I creating my first flash (actionscript 3.0) website but I'm
    stuck with a visual effect I want to create.
    I have a window on my website called contentWindow. Every
    time you click a button this window is supposed to leave the stage,
    load the requested content and return to the stage.
    The sliding window is a movie clip with 83 frames, 21 to
    enter the stage, 21 to leave the stage again, 20 for nothing (its
    just to simulate the loading time) and 21 to return to the stage.
    Now my goal is, when the user clicks on a navigation button,
    the window exits the stage, loads an external SWF with the content,
    and then returns to the stage.
    I've the "window" movie clip with an instance name of
    "contentWindow". Inside there is another movie clip with an
    instance name of "contentLoader". The content that the user
    requested should appear inside the "contentLoader".
    Now, when the contentWindow leaves the stage, I get this
    error message:
    quote:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at rwd_fla::MainTimeline/trigger()
    If I switch
    "contentWindow.contentLoader.addChild(navLoader);" for
    "contentWindow.addChild(navLoader);" it works fine, but the
    external SWF doesn't move with the window.
    How can I load an external SWF into a movie clip that's
    inside other movie clip?

    Hi,
    Recently, I have been putting together a flash presentation.
    And I am just wondering if the following might help you, in your
    communication with the said swf file:
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    onComplete);
    function onComplete(event:Event):void
    event.target.content.thinggy_mc.y -= 100;
    Not the best example, but this allows you to target a mc
    within an external swf file. I think if you look up this code, you
    will have an answer ;)
    Kind Regards,
    Boxing Boom

  • FAQ: How do I load an external SWF file into a parent SWF file?

    A ton of Flash users visit Adobe’s we site every month wondering  about how to load an external SWF file from within another SWF.
    Adobe's own TechNote on the subject attempts to answer the basic question, along with some common follow-up questions, including:
    How do I load more than one SWF?
    How do I load a SWF into a specific location in the display list?
    How do I resize the loaded SWF?
    How do I set its X and Y location?
    Here are some additional resources that elaborate on loading content and on working with the display list:
    Sample files for the above TechNote. A set of 3 FLA and 3 corresponding SWF files, including a parent SWF and 2 SWFs that the parent loads.
    Help > AS3 Developer’s Guide > Loading an external SWF file
    Help > AS3 Developer’s Guide > Loading display content dynamically
    Loading multiple external SWFs within a main SWF – CreativeCow.net forums
    Video tutorial: ActionScript 101 – Episode 6: Adding named objects to the Stage. By Doug Winnie. An example of how to add the loaded external asset to the Stage and modify its location or other properties.
    Video tutorial: Preloading in ActionScript 3.0.  By Lee Brimelow. A slightly more complicated example, showing how to  make the parent SWF display information about the progress of loading  the external SWF.
    Tutorial: Loading and unloading SWFs - FlashAndMath.com
    This article provides several examples of how to communicate between a parent SWF file and the loaded SWF:
    SWF to SWF Communcation via ActionScript 3.0 (by kglad)

    quote:
    Originally posted by:
    NedWebs
    You now seem to want to get rid of the swf once it has loaded
    and played itself thru. To do that you would need to have something
    in the swf itself that triggers its removal in its last frame. The
    following might work...
    MovieClip(this.parent).removeChild(this);
    Unfortunately I couldn't get this to work. I placed it on the
    last frame of the SWF to be called - is that right?
    I am not sure I am doing it correctly...

  • Problem with volume handle and external SWF

    Hello I'm having 2 problems.
    The first is that when loading an external swf in my main SWF I get this in the output window:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at audio_fla::list_1/frame1()
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()
    at audio_fla::MainTimeline()
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at audio_fla::MainTimeline/frame1()
    But it still works. Its an mp3 player.
    The other problem is that the loaded SWF has a volume controller. When I test the external SWF by itself it works fine. When I load it on my main SWF when I start to drag the handle on my volume slider and MOUSE_UP outside the handle it still keep dragging the handle.
    The code of my main SWF is:
    import caurina.transitions.*;
    var _currentCategory:String = "";
    var percent:String = "";
    var loader = new Loader();
    loader.name="videoLoader";
    loadermc.visible=false;
    cat.addEventListener(MouseEvent.MOUSE_OVER, onOverCat);
    cat.addEventListener(MouseEvent.MOUSE_OUT, onOutCat);
    cat.addEventListener(MouseEvent.CLICK, onClickCat);
    btnback.addEventListener(MouseEvent.MOUSE_OVER, onOverCat);
    btnback.addEventListener(MouseEvent.MOUSE_OUT, onOutCat);
    btnback.addEventListener(MouseEvent.CLICK, onClickBack);
    cat.buttonMode = true;
    btnback.buttonMode = false;
    btnback.visible = false;
    function onOverCat(e:MouseEvent):void{
         Tweener.addTween(e.target, {alpha:.5 , time:.5});
    function onOutCat(e:MouseEvent):void{
         Tweener.addTween(e.target, {alpha:.25 , time:.5});
    function onClickBack(e:MouseEvent):void{
         loader.unloadAndStop();
         loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
         lcontent.visible = false;
         cat.visible = true;
         Tweener.addTween(cat, {alpha:1, time:1});
         btnback.buttonMode = false;
         btnback.visible = false;
         cat.buttonMode = true;
         toptxt.text = "SELECCIONE UNA CATEGORIA"
    function onClickCat(e:MouseEvent):void{
         lcontent.visible=true;
         cat.buttonMode = false;
         Tweener.addTween(cat, {alpha:0, time:1, onComplete:function(){
                                  cat.visible = false;                                                       
                                  btnback.buttonMode = true;
                                  btnback.visible = true;
                                       loaderTweenIn(e.target.name);
    function loaderTweenIn (c:String):void{
         var category:String = c+".swf";
         trace(category);
         loader.load(new URLRequest(category));
         loader.contentLoaderInfo.addEventListener (Event.COMPLETE, movieLoaded);
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, movieProgress);
    function ioErrorHandler(e:IOErrorEvent):void{
         trace("ioErrorHanlder: "+e);
    function movieLoaded(e:Event):void{
         trace("The movie has loaded");
         lcontent.addChild(loader);
         loadermc.visible=false;
    function movieProgress(e:ProgressEvent):void{
         loadermc.visible = true;
    //     percent=String(Math.floor(e.bytesLoaded / e.bytesTotal * 100)) + "%";
         trace("The movie is loading "+Math.floor(e.bytesLoaded / e.bytesTotal * 100));
    The code on my external SWF is:
    import caurina.transitions.*;
    volume_mc.slider_mc.buttonMode = true;
    var myXML:XML;
    var thb:Thbs;
    var myThumbs:XMLList;
    var totalThumbs:Number;
    var thumbHeight:Number=50;
    var i:uint = 0;
    var preloader:LoaderAnim;
    var yCounter:Number = 0;
    var container:MovieClip;
    var musicReq:URLRequest;
    var music:Sound = new Sound();
    var sc:SoundChannel;
    var currentSound:Sound = music;
    var pos:Number;
    var songPlaying:Boolean = false;
    var songlist:XMLList;
    var currentIndex:Number = 0;
    mc_sound.mute.visible=false;
    var xmlLoader:URLLoader = new URLLoader();
    ///////////////////////////PLAYLIST//////////////////
    function initMediaPlayer(e:Event):void{
         myXML = new XML(xmlLoader.data);     
         myThumbs = myXML.*;
         totalThumbs = myThumbs.length();
         trace("The total thumbs are "+totalThumbs);
         createContainer();
         callThumbs();
    xmlLoader.load(new URLRequest("audio.xml"));
    function createContainer():void{
         container = new MovieClip();
         list.ch.addChild(container);
         container.y = 0;
         container.x = 0;
         container.buttonMode = true;
    function onOver(e:MouseEvent):void{
         var t:Loader = Loader(e.target);
         Tweener.addTween(t, {alpha:.5, time:1});
    function onOut(e:MouseEvent):void{     
         var t:Loader = Loader(e.target);
         Tweener.addTween(t, {alpha:1, time:1});
    function callThumbs():void{
              var thumbURL = myThumbs[i].@thumb;
              var thumbTitle:String = myThumbs[i].@title;
              var thumbDesc:String = myThumbs[i];
              trace("Loading "+thumbURL);
              trace("Title "+thumbTitle);
              trace("Desc "+thumbDesc);
              var thumbLoader = new Loader();
              thumbLoader.load(new URLRequest(thumbURL));
              thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
              thumbLoader.name=i;
              thumbLoader.x=5;
              thumbLoader.y=5;
              thb = new Thbs();
              container.addChild(thb);
              thb.thb_title.htmlText = thumbTitle;
              thb.thb_desc.autoSize = TextFieldAutoSize.LEFT;
              thb.thb_desc.htmlText = thumbDesc;
              thb.y = (thumbHeight+2)*yCounter;
              preloader = new LoaderAnim();
              preloader.x = thb.x + 20;
              preloader.y = thb.y+ 20;
              container.addChild(preloader);
              yCounter++;
    function thumbLoaded(e:Event):void{
         var thbx:Loader = Loader(e.target.loader);
         thb.addChild(thbx);
         thbx.addEventListener(MouseEvent.MOUSE_OVER, onOver);
         thbx.addEventListener(MouseEvent.MOUSE_OUT, onOut);
         container.removeChild(preloader);
         i++;
         if (i<totalThumbs){
              callThumbs();
         if (i==totalThumbs){
              startAudio();
    xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer);
    ///////////////////////////////////////AUDIO//////////////////////////
    function startAudio():void{
         songlist = myXML.*;;//this is the same as myXML.*;
         trace("This is the first song "+songlist[0].@song);
         musicReq = new URLRequest(songlist[0].@song);
         music.load(musicReq);
         sc = music.play();
         sc.addEventListener(Event.SOUND_COMPLETE, nextSong);     
    next_btn.addEventListener(MouseEvent.CLICK, nextSong);
    prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
    pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
    stop_btn.addEventListener(MouseEvent.CLICK,stopSong);
    function nextSong(e:Event):void
         if (currentIndex < (songlist.length() - 1))
              currentIndex++;
         else
              currentIndex = 0;
         var nextReq:URLRequest = new URLRequest(songlist[currentIndex].@song);
         var nextTitle:Sound = new Sound(nextReq);
         sc.stop();
         sc = nextTitle.play();
         songPlaying = true;
         currentSound = nextTitle;
         sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
    function prevSong(e:Event):void
         if (currentIndex > 0)
              currentIndex--;
         else
              currentIndex = songlist.length() - 1;
         var nextReq:URLRequest = new URLRequest(songlist[currentIndex].@song);
         var prevTitle:Sound = new Sound(nextReq);
         sc.stop();
         sc = prevTitle.play();
         songPlaying = true;
         currentSound = prevTitle;
         sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
    function pauseSong(e:Event):void
         pos = sc.position;
         sc.stop();
         songPlaying = false;
         play_btn.addEventListener(MouseEvent.CLICK,playSong);
    function playSong(e:Event):void
         if(songPlaying == false)
              sc = currentSound.play(pos);
              sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
              songPlaying = true;
              play_btn.removeEventListener(MouseEvent.CLICK,playSong);
    function stopSong(e:Event):void
         sc.stop();
         pos = 0;
         songPlaying = false;
         play_btn.addEventListener(MouseEvent.CLICK,playSong);
    ///////////////////////////////VOLUME/////////////////////////////
    var xOffset:Number;
    var xMin:Number = 0;
    var xMax:Number = volume_mc.track.width;
    volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);
    volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP, sliderUp);
    stage.addEventListener(MouseEvent.MOUSE_UP, sliderUp);
    function sliderDown(e:MouseEvent):void{
         stage.addEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
         xOffset = mouseX - volume_mc.slider_mc.x;
    function sliderUp(e:MouseEvent):void{
         stage.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
    function sliderMove(e:MouseEvent):void{
         volume_mc.slider_mc.x = mouseX - xOffset;
         if(volume_mc.slider_mc.x<=xMin){
              volume_mc.slider_mc.x = xMin;
         if(volume_mc.slider_mc.x>=xMax){
              volume_mc.slider_mc.x = xMax;
         var vol:Number = volume_mc.slider_mc.x*.01;
         var st:SoundTransform = new SoundTransform(vol,0);
         sc.soundTransform = st;
         trace("The volume is "+vol);
         if(vol==0){
              mc_sound.mute.visible=true;
         }else{
              mc_sound.mute.visible=false;
         e.updateAfterEvent();

    I found the solution.

  • Remove / unload external swf file(s) from the main flash file and load a new swf file and garbage collection from memory.

    I can't seem to remove / unload the external swf files e.g when the carousel.swf (portfolio) is displayed and I press the about button the about content is overlapping the carousel (portfolio) . How can I remove / unload an external swf file from the main flash file and load a new swf file, while at the same time removing garbage collection from memory?
    This is the error message(s) I am receiving: "TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/removeChild()
    at index_fla::MainTimeline/Down3()"
    import nl.demonsters.debugger.MonsterDebugger;
    var d:MonsterDebugger=new MonsterDebugger(this);
    stage.scaleMode=StageScaleMode.NO_SCALE;
    stage.align=StageAlign.TOP_LEFT;
    stage.addEventListener(Event.RESIZE, resizeHandler);
    // loader is the loader for portfolio page swf
    var loader:Loader;
    var loader2:Loader;
    var loader3:Loader;
    var loader1:Loader;
    //  resize content
    function resizeHandler(event:Event):void {
        // resizes portfolio page to center
    loader.x = (stage.stageWidth - loader.width) * .5;
    loader.y = (stage.stageHeight - loader.height) * .5;
    // resizes about page to center
    loader3.x = (stage.stageWidth - 482) * .5 - 260;
    loader3.y = (stage.stageHeight - 492) * .5 - 140;
    /*loader2.x = (stage.stageWidth - 658.65) * .5;
    loader2.y = (stage.stageHeight - 551.45) * .5;*/
    addEventListener(Event.ENTER_FRAME, onEnterFrame,false, 0, true);
    function onEnterFrame(ev:Event):void {
    var requesterb:URLRequest=new URLRequest("carouselLoader.swf");
    loader = null;
    loader = new Loader();
    loader.name ="carousel1"
    //adds gallery.swf to stage at begining of movie
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader.load(requesterb);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader);
    loader.x = (stage.stageWidth - 739) * .5;
    loader.y = (stage.stageHeight - 500) * .5;
    // stop gallery.swf from duplication over and over again on enter frame
    removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    //PORTFOLIO BUTTON
    //adds eventlistner so that gallery.swf can be loaded
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    function Down(event:MouseEvent):void {
    // re adds listener for contact.swf and about.swf
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    //unloads gallery.swf from enter frame if users presses portfolio button in nav
    var requester:URLRequest=new URLRequest("carouselLoader.swf");
        loader = null;
    loader = new Loader();
    loader.name ="carousel"
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader);
    loader.x = (stage.stageWidth - 739) * .5;
    loader.y = (stage.stageHeight - 500) * .5;
    removeChild( getChildByName("about") );
    removeChild( getChildByName("carousel1") );
    // remove eventlistner and prevents duplication of gallery.swf
    MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
    //INFORMATION BUTTON
    //adds eventlistner so that info.swf can be loaded
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    function Down1(event:MouseEvent):void {
    //this re-adds the EventListener for portfolio so that end user can view again if they wish.
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    var requester:URLRequest=new URLRequest("contactLoader.swf");
    loader2 = null;
    loader2 = new Loader();
    loader2.name ="contact"
    loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader2.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader2);
    loader2.x = (stage.stageWidth - 658.65) * .5;
    loader2.y = (stage.stageHeight - 551.45) * .5;
    // remove eventlistner and prevents duplication of info.swf
    MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
    //ABOUT BUTTON
    //adds eventlistner so that info.swf can be loaded
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    function Down3(event:MouseEvent):void {
    //this re-adds the EventListener for portfolio so that end user can view again if they wish.
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    var requester:URLRequest=new URLRequest("aboutLoader.swf");
    loader3 = null;
    loader3 = new Loader();
    loader3.name ="about"
    loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader3.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader3);
    loader3.x = (stage.stageWidth - 482) * .5 - 260;
    loader3.y = (stage.stageHeight - 492) * .5 - 140;
    removeChild( getChildByName("carousel") );
    removeChild( getChildByName("carousel1") );
    // remove eventlistner and prevents duplication of info.swf
    MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
    stop();

    Andrei1,
    Thank you for the helpful advice. I made the changes as you suggested but I am receiving a #1009 error message even though my site is working the way I wan it to work. I would still like to fix the errors so that my site runs and error free. This is the error I am receiving:
    "TypeError: Error #1009: Cannot access a property or method of a null object reference."
    I'm sure this is not the best method to unload loaders and I am guessing this is why I am receiving the following error message.
         loader.unload();
         loader2.unload();
         loader3.unload();
    I also tried creating a function to unload the loader but received the same error message and my portfolio swf was not showing at all.
         function killLoad():void{
         try { loader.close(); loader2.close; loader3.close;} catch (e:*) {}
         loader.unload(); loader2.unload(); loader3.unload();
    I have a question regarding suggestion you made to set Mouse Event to "null". What does this do setting the MouseEvent do exactly?  Also, since I've set the MouseEvent to null do I also have to set the loader to null? e.g.
    ---- Here is my updated code ----
    // variable for external loaders
    var loader:Loader;
    var loader1:Loader;
    var loader2:Loader;
    var loader3:Loader;
    // makes borders resize with browser size
    function resizeHandler(event:Event):void {
    // resizes portfolio page to center
         loader.x = (stage.stageWidth - loader.width) * .5;
         loader.y = (stage.stageHeight - loader.height) * .5;
    // resizes about page to center
         loader3.x = (stage.stageWidth - 482) * .5 - 260;
         loader3.y = (stage.stageHeight - 492) * .5 - 140;
    //adds gallery.swf to stage at begining of moviie
         Down();
    //PORTFOLIO BUTTON
    //adds eventlistner so that gallery.swf can be loaded
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    function Down(event:MouseEvent = null):void {
    // re adds listener for contact.swf and about.swf
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    //unloads gallery.swf from enter frame if users presses portfolio button in nav
         var requester:URLRequest=new URLRequest("carouselLoader.swf");
         loader = new Loader();
         loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader.load(requester);
         } catch (error:SecurityError) {
         trace(error);
         this.addChild(loader);
         loader.x = (stage.stageWidth - 739) * .5;
         loader.y = (stage.stageHeight - 500) * .5;
    // sure this is not the best way to do this - but it is unload external swfs
         loader.unload();
         loader2.unload();
         loader3.unload();
    // remove eventlistner and prevents duplication of gallery.swf
         MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
    //INFORMATION BUTTON
         //adds eventlistner so that info.swf can be loaded
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         function Down1(event:MouseEvent = null):void {
         //this re-adds the EventListener for portfolio so that end user can view again if they wish.
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
         var requester:URLRequest=new URLRequest("contactLoader.swf");
         loader2 = null;
         loader2 = new Loader();
         loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);    
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader2.load(requester);
    }      catch (error:SecurityError) {
         trace(error);
         addChild(loader2);
         loader2.x = (stage.stageWidth - 658.65) * .5;
         loader2.y = (stage.stageHeight - 551.45) * .5;
    loader.unload();
    loader2.unload();
    loader3.unload();
         // remove eventlistner and prevents duplication of info.swf
         MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
    //ABOUT BUTTON
         //adds eventlistner so that info.swf can be loaded
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
         function Down3(event:MouseEvent = null):void {
         //this re-adds the EventListener for portfolio so that end user can view again if they wish.
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         var requester:URLRequest=new URLRequest("aboutLoader.swf");
         loader3 = null;
         loader3 = new Loader();
         loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader3.load(requester);
    }      catch (error:SecurityError) {
         trace(error);
         addChild(loader3);
         loader3.x = (stage.stageWidth - 482) * .5 - 260;
         loader3.y = (stage.stageHeight - 492) * .5 - 140;
         loader.unload();
         loader2.unload();
         loader3.unload();
         // remove eventlistner and prevents duplication of info.swf
         MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
         stop();

  • Loading external swf  not complete

    Hi, I'm trying to load external swf (with more than one frame and actionscript 3 on every frame - I used there "timeline" coding) from my main swf.
    code for loading external swf into main swf:
    var loader01:Loader;
    function openGame1(evt:Event):void
    loader01 = new Loader();
    var requestSWF01:URLRequest = new URLRequest("game01.swf");
    loader01.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, processHandler);
    loader01.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
    loader01.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
    loader01.load(requestSWF01);
    addChild(loader01);
    function processHandler(evt:ProgressEvent):void
    var loaded:Number=evt.target.bytesLoaded;
    var total:Number=evt.target.bytesTotal;
    var stav:Number=loaded/total;
    loaded_txt.text=(Math.round(stav*100))+" %";
    function initHandler(evt:Event):void{
    loaded_txt.text="";
    function errorHandler(evt:IOErrorEvent):void
         trace ("Error: " + evt.text);
    I found out that this works only for loading swf, which has only one frame (and all actionscript on that frame)... It seems that if there are more frames, than it will not load complete swf (hmm maybe it is caused, because not all objects on frames are export in first frame). Preloading starts but after for example 20 % the event.INIT is fired and the external swf starts to play (and crashes..).
    You can see this here http://bvyborcik.xf.cz/  If you click on the blue building on the left with blinking text "Start hry" you will see what happens - preloading is not completed and after clicking on first floor btn, the swf crashes...
    Please is there a solution for this kind of problem?  Any help or pointing is welcome.
    regards Boris

    just curious, is the file you want to load the swf into set up exactly the same way with the same stage size, fps, and layers?

  • Trouble loading external .SWF into my main page with preloaders

    Dear All,
    I am working on my first Flash project with AS3.
    The structure of the flash site is pretty simple. I have a
    stage 1165px wide x 710px height
    Inside my Stage I have an horizontal bar with a menu followed
    by a container right under.
    **** My goal
    is that whenever I click on one of the button on the menu, that the
    related external .SWF loads into
    the container with a preloading bar and %. *****
    I already did all my .SWF files and it is pretty frustrating
    at this point to be stuck at this point of development.
    Please help.
    -Alex

    Visit gotoandlearn.com. There is a video tutorial there
    regarding preloading that should answer most, if not all, of your
    wonderings.

Maybe you are looking for