Jump to content
Search Community

Trouble with DataLoader

failure13 test
Moderator Tag

Recommended Posts

Technically you could create a URLStream...

I became really interested, and try...If i use Event.COMPLETE instead ProgressEvent.PROGRESS - it works fine, reliable (memory is nice too), but what about ProgressEvent.PROGRESS?

Please, check if i have understood you right (if you don't want to waste your time on non gs related questions - i'll understand):

var stream:URLStream;
var request:URLRequest;

// function that loads next URL until it fails to find valid combination
function loadImagesURL():void {
// load next URL index
currentNum++;
// current URL path, that replaces ## in IMGpath for a numbers
currentURL = IMGpath.replace("##", currentNum);
request = new URLRequest(currentURL);
stream = new URLStream();
// pass new URL to loader
stream.load(request);
stream.addEventListener(ProgressEvent.PROGRESS, onNextComplete);
stream.addEventListener(IOErrorEvent.IO_ERROR, onNextError);
}

// function that adds URL inside an array
function onNextComplete():void {
// add current URL inside an array
imagesURL.push(currentURL);
// for first written URL
if (currentNum == 1) {
	// name & add controls on stage
	galleryControls.name = "galleryControls";
	addChild(galleryControls);
	// create an XML text
	textXML();
	// slowly change alpha of controls to let it appear
	TweenMax.to(galleryControls, loadAnimTime,{alpha: 1, delay: 0.14, onStart: function() {galleryControls.alpha = 0} });
}
// load next URL
loadImagesURL();
}

// function that stop searching for images when there are no URL availible
function onNextError():void {
trace(imagesURL);
stream.removeEventListener(ProgressEvent.PROGRESS, onNextComplete);
stream.removeEventListener(IOErrorEvent.IO_ERROR, onNextError);
// start listen for keys
stage.addEventListener(KeyboardEvent.KEY_DOWN, reactToArrowKeys);
// set up buttons array
for (var i:int = 0; i < galleryButtonsArray.length; i++) {
	// add listeners for previous / next click
	galleryButtonsArray[i].addEventListener(MouseEvent.CLICK, imageButtonsActions);
}
}

 

This way when i trace(imagesURL); last written url is usually something like system/gallery/patr/picture1217.jpg, but actually in my folder there are 11 files...So if use ProgressEvent, it can't stop in time, when IOError happens, right?

 

P.S. and also, do i need to unload stream somehow, after it have been (or when i dispose whole gallery) done or it's automatically?

Link to comment
Share on other sites

The reason you're having trouble with the PROGRESS events is because you never close() your NetStream, so it continues to dispatch PROGRESS events until it completes, but your code is creating a new NetStream EVERY time a PROGRESS event occurs! The first file might dispatch 50 PROGRESS events (or more, or less), each of which is trying to create a new URLStream, and each of those is doing exactly the same thing again so the problem is compounded exponentially. You could easily end up with 1000+ URLStreams.

 

Like I said, be careful about going to go down this path of manually creating URLStreams. It's easy to get yourself in trouble :)

 

As far as the need to unload your NetStream, yes, please see Adobe's documentation about that. You should definitely be closing them. You might want to listen for security errors as well.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...