|
-
[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, _loaderCompleteHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, _ioErrorHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener (IOErrorEvent.DISK_ERROR, _ioErrorHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener (IOErrorEvent.NETWORK_ERROR, _ioErrorHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener (IOErrorEvent.VERIFY_ERROR, _ioErrorHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, _backgroundProgressHandler, false, 0, true);
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, _moduleReadyToShowHandler, false, 0, true);
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);
}
-
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.
-
sorry to ask. but how would one go about doing that
-
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;
}
-
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.
-
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
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|