Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
baldscone

LoaderMax alternateURL and parse method

Recommended Posts

Hi - Ive been trying to get alternateURL along with LoaderMax's parse method to work locally but I still get a stream error when I try to use alternateURL to provide an alternate image. I am referencing a local file in my build directory - does it only work online maybe?

Ive also tried separating it out and building up the loaders by extension type but that still doesn't seem to work. I know some users have had problems in the past using audit size - Ive tried turning that off and on - no luck.

 

I have also updated from my account with the latest SWC (v11) and this is the code I am using.

//assetURLs is passed into this method with a mixture of .pngs, .jpgs and .swfs

var loaderVars:LoaderMaxVars = new LoaderMaxVars();

loaderVars.onComplete(onComplete);

loaderVars.onError(onError);

loaderVars.onIOError(onError);

loaderVars.onFail(onError);

loaderVars.onProgress(onProgress);

//loaderVars.auditSize(false);//Ive tried this but it doesn't make a difference

//For images add missing icon

var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();

imageLoaderVars.noCache(true);

imageLoaderVars.smoothing(true);

imageLoaderVars.alternateURL("missing/default.jpg");

LoaderMax.activate([imageLoader, SWFLoader]);

loaderQueue = LoaderMax.parse(assetURLs, loaderVars, imageLoaderVars);

loaderQueue.load();

Link to comment
Share on other sites

So - just to be clear - I have tried this method also but no luck either:

 

for each (var assetURL:String in assetURLs)
{
//What type of asset is it?
var type:String = StringUtils.getFileExtension(assetURL);

switch (type)
{
case "swf":
loaderQueue.append(new SWFLoader(assetURL));
break;
case "png":
loaderQueue.append(new ImageLoader(assetURL,imageLoaderVars));
break;
case "jpg":
loaderQueue.append(new ImageLoader(assetURL,imageLoaderVars));
break;
default:
var errorEvent:AppEvent = new AppEvent(AppEvent.APP_ERROR);
errorEvent.errorStr = "AssetLoaderService.load unknown file type: " + type;
dispatch(errorEvent);
break;
}
}

Link to comment
Share on other sites

Hi.

 

thanks for providing the code. I made some slight modifications and it worked fine.

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.loading.data.*;
import com.greensock.events.*;

var assetURLs:Array = ["idontexist.jpg"];
var loaderVars:LoaderMaxVars = new LoaderMaxVars();

//For images add missing icon
var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();
imageLoaderVars.noCache(true);
imageLoaderVars.smoothing(true);


//NEW
imageLoaderVars.container(this);
imageLoaderVars.onComplete(done);
imageLoaderVars.alternateURL("f.jpg");
//END NEW

LoaderMax.activate([imageLoader, SWFLoader]);
var loaderQueue:LoaderMax = LoaderMax.parse(assetURLs, loaderVars, imageLoaderVars);
loaderQueue.load();

function done(e:LoaderEvent):void{
trace("loading done");
}

 

-i removed all the event listeners on the LoaderMaxVars just so that i didn't have to create them

-I added a container property which is necessary in order to see the image

 

also, you will still see the runtime stream error as idontexists.jpg does fail to load, but my alternateURL("f.jpg") image loads ok and the complete event fires.

tested locally and online.

 

does this help?

Link to comment
Share on other sites

Hi Carl,

Thanks for your post. I have this class as a service class (so no container/view class) which looks like what is my problem. Any idea if alternateURL will work with a separated MVC pattern? I was hoping I could later try LoaderMax.getContent(my url) and get back my default image...but not sure i can?

 

Any ideas?

Link to comment
Share on other sites

ignore that css stuff. it appears the forum's code formatter is a little weird sometimes. that line should just be:

 

 

imageLoaderVars.alternateURL("f.jpg");

 

f.jpg is just the name of my test image.

each ImageLoader you create has a content property which refers to its special "ContentDisplayObject" that holds the loaded bitmap.

as long you can find each ImageLoader, you can addChild() its content whenever and wherever you want.

 

something like

addChild( LoaderMax.getContent("someImage.jpg") );

Link to comment
Share on other sites

Mmm - strange - I passed in a reference to the main view just to see what happens. The default (alternateURL) image is displayed, but when I call

 

var thumbNail:ContentDisplay = LoaderMax.getContent("idontexist.jpg");
trace(thumbNail);//traces null

 

It traces null?

So it sort of works but not how I need it to. I would like to be able to get a default missing image for the thumbnail image if it is missing, but later on in the application's life cycle (i.e. not straight away into a view object)

So back to scratching my head... My work around could be to save the ContentDisplay somewhere and use that later if thumbnail returns null.

Link to comment
Share on other sites

What happens when you simply do this?:

trace(LoaderMax.getContent("idontexist.jpg"));

Does it trace a Loader object? Just keep in mind that if LoaderMax runs into a security problem (like if you're loading from another domain that doesn't have a crossdomain.xml file in place), it will automatically fall back to a more permissive state and try again, but one consequence is that the content must be a Loader at that point due to Flash's requirements. It really has nothing to do with LoaderMax per se - there's no way around that limitation in Flash. So I'm just wondering if when you tried casting to a ContentDisplay, that could result in the variable being null.

Link to comment
Share on other sites

Firstly it throws an error:

 

Error on ImageLoader 'loader4' (thumbnails/quickstart_tips.png): Error #2032: Stream Error. URL: file:///Volumes/BaldsconeHD/Current Projects/USB/images/bin-debug/thumbnails/quickstart_tips.png

 

and when I try:

trace("LoaderMax.getContent: " +LoaderMax.getContent(videoCollectionData.thumbnail));
//returns LoaderMax.getContent: null

No cross domain or security errors.

Error 2032 is an IOError right? Stumped.

Link to comment
Share on other sites

A Stream Error typically means it can't find the file at the URL you provided. Bad path.

Link to comment
Share on other sites

  • 3 weeks later...

I still haven't managed to solve this and Ive tried everything I can think of. Ive triple checked the path and tried different image paths. Can you suggest anything else I can try? Ive included the full trace below and code again. Any help would be greatly appreciated. Im stumped!

 

Ive implemented a workaround but I would prefer to use alternateURL for flexibility.

 

public function load(assetURLs:Array):void
{
trace("AssetLoaderService.load(assetURLs) - " + assetURLs);
var loaderVars:LoaderMaxVars = new LoaderMaxVars();
loaderVars.onComplete(onComplete);
loaderVars.onError(onError);
loaderVars.onIOError(onError);
loaderVars.onFail(onError);
loaderVars.onProgress(onProgress);

//For images add missing icon
var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();
imageLoaderVars.alternateURL("http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Status-image-missing-icon.png");
imageLoaderVars.noCache(true);//appends cache (helps with multiple images - but only from a server)
imageLoaderVars.smoothing(true);
LoaderMax.activate([imageLoader, SWFLoader]);//Can also use VideoLoader and Mp3Loader
loaderQueue = LoaderMax.parse(assetURLs, loaderVars, imageLoaderVars);//one of these URLS is "thumbnails/Idontexist.png"
loaderQueue.load();

}
/* AND LATER IN ANOTHER VIEW CLASS */
for each (var videoCollectionData:VideoCollectionData in event.playlistData.videoCollections)
{
trace(LoaderMax.getContent("thumbnails/Idontexist.png"));

var thumbNail:ContentDisplay = LoaderMax.getContent(videoCollectionData.thumbnail);
view.addPlaylistItem(videoCollectionData, thumbNail);
}

/*TRACE IS*/

AssetLoaderService.load(assetURLs) - background.jpg,logo.png,thumbnails/Idontexist.png,thumbnails/synthesis.png,thumbnails/key_commands.png
LoadAssetsCommand.onError() - Error #2032: Stream Error. URL: file:///Volumes/BaldsconeHD/Dropbox/Dropbox/Current_Projects/Deepbase Jobs 2012/Multitech USB Cloud Key/development/bin-debug/thumbnails/Idontexist.png
----
Error on ImageLoader 'loader4' (thumbnails/Idontexist.png): Error #2032: Stream Error. URL: file:///Volumes/BaldsconeHD/Dropbox/Dropbox/Current_Projects/Deepbase Jobs 2012/Multitech USB Cloud Key/development/bin-debug/thumbnails/Idontexist.png
----
LoadAssetsCommand.onError() - ImageLoader 'loader4' (thumbnails/Idontexist.png) > Error #2032: Stream Error. URL: file:///Volumes/BaldsconeHD/Dropbox/Dropbox/Current_Projects/Deepbase Jobs 2012/Multitech USB Cloud Key/development/bin-debug/thumbnails/Idontexist.png

Link to comment
Share on other sites

Yeah, that error definitely means you've got a bad URL (or at least Flash can't get the file there). Feel free to post a zipped folder of all your assets along with the FLA that we can publish to see what's going on. If you can simplify things to only the essential elements to reproduce the error, that's best.

Link to comment
Share on other sites

 

Hi there,

 

Thanks for your reply.

 

Ive put together a simplified example to demonstrate the problem. Ive used Carls' simplified code from earlier in this post. Basically it narrows down the problem being that it all works fine if you use a container to load the image into ie.

imageLoaderVars.container(this);

but if you want to put this code in a non view class and then call

LoaderMax.getContent("idontexist.jpg");

it throws a stream error. Im pretty sure its not because it can't find the alternateURL image as you suggest, unless Im mis-understanding how this function should work in LoaderMax?

 

Ive attached the simple FlashBuilder project to demonstrate. Ive also tried calling the loader but still no luck.

 

 

trace(LoaderMax.getLoader("idontexist.jpg"));//traces null

AlternateURLTest.zip

Link to comment
Share on other sites

I think I see the problem - you're trying to get the loader based on the OLD/FAILED file URL rather than the correct/loaded one. In your example, idontexist.jpg doesn't exist, so the ImageLoader switches to the alternateURL that you defined ("video_thumbnail_missing.jpg") and loads it properly. But you're passing the bad file URL to getContent() and since that file didn't load properly, it correctly returns null. You should be passing "video_thumbnail_missing.jpg" to getContent(). Once I corrected that in your file, things seemed to work perfectly. Does that clear things up?

 

By the way, if you want to use a consistent string to reference that loader, just give it a name because that'll be the same regardless of what URL loads (normal or alternate).

Link to comment
Share on other sites

Thanks for the prompt reply and explanation - I actually just found the same solution but wasn't quite sure why it worked by just naming the ImageLoader with the URL as you suggest: imageLoaderVars.name("idontexist.jpg");

I suppose I just figured that if it was an alternateURL it wouldn't matter if I called it with the bad URL and it would return something if there had been an alternate image supplied.

Thanks for the help.

Cheers

 

P.S.

Any idea how I can integrate this solution when using parse?

Link to comment
Share on other sites

You could just apply the name(s) after parsing, directly to the ImageLoader instance(s). I suppose you could even use the original URL as the name if you want.

Link to comment
Share on other sites

Thanks for your help again - its working beautifully now with just:

 

 

 

loaderQueue = LoaderMax.parse(assetURLs, loaderVars, imageLoaderVars);

 

for (var i:int = 0, index:int = loaderQueue.numChildren; i < index; i++)

{

var loader:* = loaderQueue.getChildAt(i);

if(loader is ImageLoader){

ImageLoader(loader).name = ImageLoader(loader).url;

}

}

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.
×