Hi, I am iphone and sparrow noob, and im sorry if this has been explained before.
I am trying to create a simple flickr image viewer, and not able to figure out how to load an SPImage form a url.
Any suggestions?
thanks
Hi, I am iphone and sparrow noob, and im sorry if this has been explained before.
I am trying to create a simple flickr image viewer, and not able to figure out how to load an SPImage form a url.
Any suggestions?
thanks
Hi,
I created a tutorial for that, you will have to dig into Sparrow source and get your hands alittle dirty though. It's not hard though.
You can find the tutorial here: http://shilo.coarsemode.com/sparrow/addons/#8A
Once you are done with the tutorial, there are 2 methods you can use.
1. [SPImage imageWithContentsOfWebFileBlocked:@"URL_HERE"]
This method will block the main thread until the image fully loads. I don't recommend this method, but it should be fine if you call this method on the initialization of your stage and the image is relatively small.
2. [SPImage imageWithContentsOfWebFile:@"URL_HERE"]
This method will not block the main thread and it will dispatch an event when the image is loaded. I recommend this method.
Here is an example:
- (id)initWithWidth:(float)width height:(float)height { if (self = [super initWithWidth:width height:height]) { NSString *sparrowLogoPath = @"http://www.sparrow-framework.org/wp-content/uploads/2010/03/sparrow-logo.png"; //initialize image1 and add event handler for when it loads SPImage *image1 = [SPImage imageWithContentsOfWebFile:sparrowLogoPath]; [image1 addEventListener:@selector(onImage1Loaded:) atObject:self forType:SP_EVENT_TYPE_IMAGE_LOADED]; [self addChild:image1]; //initialize image2 and wait for it to load SPImage *image2 = [SPImage imageWithContentsOfWebFileBlocked:sparrowLogoPath]; [self addChild:image2]; } return self; } - (void)onImage1Loaded:(SPEvent *)event { SPImage *image1 = (SPImage *)event.target; [image1 removeEventListener:@selector(onImage1Loaded:) atObject:self forType:SP_EVENT_TYPE_IMAGE_LOADED]; //modify image1 after it has loaded }
Thanks a lot shilo! I got it working now.
You must log in to post.