A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] As3 multiple request handling

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Posts
    26

    resolved [RESOLVED] As3 multiple request handling

    Hi

    I have a bit of code listens for a user to click a navigation item, however if they click another nav item then my code loads both of them and puts the content pages on top of each other.

    Thanks, I am having loads of problems with this bit of code.

    PHP Code:
    private function _menuSelectHandler (event MenuEvent):void {

                if (! 
    event.abstract) {

                    
    _fader.fadeOut ();
                    var 
    item:MenuItem event.target as MenuItem;
                    var 
    data:XML item.getData();



                    if (
    data. @ type !== "" && "@type"in data && data. @ content !== "" && "@content"in data) {
                        
                        var 
    loader Loader = new Loader();
            
                        
    loader.contentLoaderInfo.addEventListener (Event.COMPLETE_loaderCompleteHandlerfalse0true);
                        
    loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR_ioErrorHandlerfalse0true);
                        
    loader.contentLoaderInfo.addEventListener (IOErrorEvent.DISK_ERROR_ioErrorHandlerfalse0true);
                        
    loader.contentLoaderInfo.addEventListener (IOErrorEvent.NETWORK_ERROR_ioErrorHandlerfalse0true);
                        
    loader.contentLoaderInfo.addEventListener (IOErrorEvent.VERIFY_ERROR_ioErrorHandlerfalse0true);


                        
    loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS_backgroundProgressHandlerfalse0true);



                        
    loader.load (new URLRequest(data.@type ".swf"));
                        
                


                    }
                }
            }



            private function 
    _loaderCompleteHandler (event Event):void {
                var 
    loader Loader = (event.currentTarget as LoaderInfo).loader;

                var 
    module:Module loader.content as Module;
                
    module.loadData (_menu.selectedItem.getData().@content);
                
    module.addEventListener (Module.READY_TO_SHOW_moduleReadyToShowHandlerfalse0true);


                var 
    bgSrc:String _menu.selectedItem.getData(). @ bg_src;


                
    _preloader.hide ();

            }


    /*Loads Modules to screen*/
            
    private function _moduleReadyToShowHandler (event Event):void {
                var 
    module:Module event.currentTarget as Module;
                
    _fader.fadeTo (module);
            } 

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You need to keep a variable for the current content, and when putting up new content check that variable. If it's not empty, then remove the current content. Then put up the new content and set the variable to it.

  3. #3
    Junior Member
    Join Date
    Oct 2007
    Posts
    26
    sorry to ask. but how would one go about doing that

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Where do you actually put the items on the stage? I'll assume it's part of fader.
    Code:
    //inside fader
    private var currentContent:DisplayObject = null;
    
    //if content is added in fadeTo
    public function fadeTo(mod:Module):void{
      if (currentContent != null){
         removeChild(currentContent);
      }
      //existing code which adds mod to display list and fades it in.
      currentContent = mod;
    }

  5. #5
    Junior Member
    Join Date
    Oct 2007
    Posts
    26
    Just reading your reply again and I am not sure you understand my problem.
    You see the problem comes when the user clicks 2 different navigation items twice quickly. This causes the loader to load both pages, which then displays both.

  6. #6
    Junior Member
    Join Date
    Oct 2007
    Posts
    26
    I think i need to somehow clear the load process once you click to go to another page.
    Which I dont know how to do

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oh. Then you will want to either disallow loading another while one is already loading, or abort the first and start the second. If you go with the abort approach, it seems that GTween (which I think you are using) has pause and beginning methods which you could use to reset the first item back to it's inactive state.

  8. #8
    Junior Member
    Join Date
    Oct 2007
    Posts
    26
    I have tried to unload and close the loader but it will not do it.
    I have the idea where I can disable the Navigation while the page is loading to solve the problem.

Tags for this Thread

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