A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Problem loading external files

  1. #1
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107

    Problem loading external files

    I'm sorry if this is somewhere else on the forum. I searched and couldn't find it anywhere. It seems to me like it should be a simple problem, but I just can't figure it out...

    I have a file that loads an external swf on the click of a button. I am able to load and remove the file perfectly fine, but once I unload it, I can't load it a second time if the button is pressed again.

    Also, I have two separate external files loading when respective buttons are clicked, and whenever one is loaded, the other can't be loaded correctly simultaneously, and once one is removed, the other won't load either.

    So I can load one or the other movie clip once, but once it's been loaded and removed, nothing else will load. My code is below. Does anyone know why this might be?

    Code:
    // this opens the photo gallery.
    
    var photoloader:Loader = new Loader();
    var outside:URLRequest = new URLRequest("index.swf");
    
    this.photo_btn.addEventListener(MouseEvent.MOUSE_DOWN, photoOpen);
    
    function photoOpen(event:MouseEvent):void {
    	photoloader.load(outside);
    	addChild(photoloader);
    	photoloader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    	this.photogal_close_btn.x = 1100;
    }
    
    // end
    
    // this closes the photo gallery
    
    function onComplete(event):void {
    	this.photo_btn.removeEventListener(MouseEvent.MOUSE_DOWN, photoOpen);
    	this.photogal_close_btn.addEventListener(MouseEvent.MOUSE_DOWN, photoClose);
    }
    
    function photoClose(event:MouseEvent):void {
    	this.photoloader.unload();
    	this.photogal_close_btn.x = 1300;
    	this.photo_btn.addEventListener(MouseEvent.MOUSE_DOWN, photoOpen);
    }
    
    // end
    
    // this opens the artist gallery.
    
    var artistloader:Loader = new Loader();
    var artistoutside:URLRequest = new URLRequest("artist.swf");
    
    this.artist_btn.addEventListener(MouseEvent.MOUSE_DOWN, artistOpen);
    
    function artistOpen(event:MouseEvent):void {
    	artistloader.load(artistoutside);
    	addChild(artistloader);
    	artistloader.contentLoaderInfo.addEventListener(Event.COMPLETE, onArtistComplete);
    	this.artist_close_btn.x = 1100;
    }
    
    // end
    
    // this closes the artist gallery
    
    function onArtistComplete(event):void {
    	this.artist_btn.removeEventListener(MouseEvent.MOUSE_DOWN, artistOpen);
    	this.artist_close_btn.addEventListener(MouseEvent.MOUSE_DOWN, artistClose);
    }
    
    function artistClose(event:MouseEvent):void {
    	this.artistloader.unload();
    	this.artist_btn.addEventListener(MouseEvent.MOUSE_DOWN, artistOpen);
    	this.artist_close_btn.x = 1300;
    }
    
    // end
    Thanks!
    Last edited by Marty0473; 01-02-2009 at 12:34 PM.
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The unload() function in CS3, player 9, is buggy. If you need to unload without loading a new object you need to remove the Loader and add it back when loading another object again.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    cancerinform,

    Thanks for the reply! One more question...

    What would the code to remove the loader look like?

    Thanks again!
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    if(photoloader!=null)
    {
    removeChild(photoloader);
    }

    and then you can add it again.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    I'm sorry to keep bothering about this. I think I'm just not quite getting something. I'm very new to as3, and it's been a long time since I've worked with as2.

    Could you explain this in a little more detail, and maybe show me how it would fit in with my code? I've been working on this for hours, but am still confused.

    Thanks
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    For example here:

    function photoClose(event:MouseEvent):void {
    if(photoloader!=null)
    {
    removeChild(photoloader);
    addChild(photoloader);
    }
    this.photogal_close_btn.x = 1300;
    this.photo_btn.addEventListener(MouseEvent.MOUSE_D OWN, photoOpen);
    }
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    I still can't get that to work. Here are my files. Do you think you could take a look at them?

    http://testing.reimaginedesigns.com/pm3/pm3.zip
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  8. #8
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    Please someone?... I'm really lost here...
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The problem is that you place everything into separate functions like function go(). I looked at your movie and came up with solving the first problem, which I posted. I am not exactly sure how your movie works, what the time breaks are etc. I think you need to simplify the movie and code more straightforward.
    - The right of the People to create Flash movies shall not be infringed. -

  10. #10
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    Ok... I may have more accurately identified the problem. I found this code on another forum:

    Code:
    // Container
    var swfLoader:Loader = new Loader();
    swfLoader.x = 125;   
    swfLoader.y = 80;
    
    // Url Requests
    var swfRequestOne:URLRequest = new URLRequest("1.swf");
    var swfRequestTwo:URLRequest = new URLRequest("2.swf");
    var swfRequestThree:URLRequest = new URLRequest("3.swf");
    
    //Tell MovieClips they are Buttons
    btnOne.buttonMode = true;
    btnTwo.buttonMode = true;
    btnThree.buttonMode = true;
    
    // Button Functions
    function swfOne (e:MouseEvent):void
    {
       swfLoader.load(swfRequestOne);
       addChild(swfLoader);
    }
    btnOne.addEventListener(MouseEvent.CLICK, swfOne);
    
    function swfTwo (e:MouseEvent):void
    {
       swfLoader.load(swfRequestTwo);
       addChild(swfLoader);
    }
    btnTwo.addEventListener(MouseEvent.CLICK, swfTwo);
    
    function swfThree (e:MouseEvent):void
    {
       swfLoader.load(swfRequestThree);
       addChild(swfLoader);
    }
    btnThree.addEventListener(MouseEvent.CLICK, swfThree);
    The forum can be seen here.

    Using this code, I realized that the problem is not loading different movie clips. I created another movie that is simple and static, and it loads fine after loading either of the others. The problem is clearly with the files I'm loading. They are both xml loaders, and have quite a bit of as in them. They are also build on as2. I don't know if some, or all of these are the problem, but I know now that the problem is the files themselves.

    My question then, is: How can I completely remove the file?

    From reading, it seems that unloading using this method still leaves the swf loaded in the memory, and I'm afraid this may be the problem. How can I completely delete it, so that the next time I try to open it, it is as if I was opening the file for the first time?

    Thanks,
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  11. #11
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    First of all sorry for my wrongly placed answer. It was for a different thread.

    The point is that the problem could be that it is an AS2 movie. I have found that AS2 movies containing components screw up when loaded into an AS3 movie. I don't know your movie contains components, however I would not be surprised if something else could also screw up the movie.
    As far as I know movies only stay in cache memory of the browser. So the problem may be that the loaded movie has done something to your parent movie, which remains.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center