Unable to get Content from Loaded Facebook Images
eduardo3r opened this issue · 1 comments
Hello:
I am using BulkLoader to load images from a users Friends list in Facebook.
Facebook uses an ID (like mine: 6311111196)
And any users Picture can be accessed through :
"https://graph.facebook.com/631111196/picture"
Which redirects to another link with the actual picture:
"http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs231.ash2/49539_631111196_6291_q.jpg"
ISSUE: using any of these two paths, I am able to load the image as shown by the BulkLoader.PROGRESS event. I compared the file size and it matches. But I am unable to retrieve the content and keep on getting a null handler for any of these methods:
var content : * = loader.getContent(imageURL); // use getContent to load images
var bgBitmap : Bitmap = content as Bitmap;
someSprite = loader.getSprite(imageURL);
someSprite = loader.getSprite("bg");
someBitmap = loader.getBitmap("bg");
someBitmap = loader.getBitmap(imageURL);
In short, any loading method I use, using URL or URLRequest loads the image succesfully, but it cannot be retrieved.
I have narrowed down the code, and will post it here as well.
This is the narrowed down version of the code:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%" height="100%"
applicationComplete="init()"
>
fx:Declarations
/fx:Declarations
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
import flash.display.Sprite;
// Bulk loader class
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;
// instance loader
public var loader:BulkLoader = new BulkLoader();
protected var uiComponent:UIComponent = new UIComponent();
//private var imageURL:String = "https://graph.facebook.com/631111196/picture" ;
private var imageURL:String = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs231.ash2/49539_631111196_6291_q.jpg" ;
private var imageHolders:Array = new Array();
protected function init():void {
mainCanvas.addChild(uiComponent);
loadImages();
}
public function onAllError(e:Event):void {
// catch loading error reports
errorText.text = "CAUGHT ERROR" ;
}
public function onAllItemsProgress(e:BulkProgressEvent):void {
// monitor image loading progress.
progressText.text = progressText.text + "\n " + String(e.loadingStatus());
}
public function onAllItemsLoaded(e:Event):void {
// hold images
var picHolder:Sprite = new Sprite();
var someBitmap : Bitmap = new Bitmap();
var someSprite : Sprite = new Sprite();
var content : * = loader.getContent(imageURL); // use getContent to load images
var bgBitmap : Bitmap = content as Bitmap;
// grab as a Sprite
//someSprite = loader.getSprite("bg");
someSprite = loader.getSprite(imageURL);
// grab as an Image
//someBitmap = loader.getBitmap("bg");
someBitmap = loader.getBitmap(imageURL);
if( bgBitmap == null ) {
resultText.text = resultText.text + "\n bgBitmap NULL ";
}
else {
picHolder.addChild(bgBitmap);
resultText.text = resultText.text + " \n bgBitmap SUCCESS!";
}
if( someSprite == null ) {
resultText.text = resultText.text + "\n SPRITE NULL ";
}
else {
picHolder.addChild(someSprite);
resultText.text = resultText.text + " \n SPRITE SUCCESS!";
}
if( someBitmap == null ) {
resultText.text = resultText.text + "\n BITMAP NULL";
}
else {
picHolder.addChild(someBitmap);
resultText.text = resultText.text + "\n BITMAP SUCCESS!";
}
uiComponent.addChild(picHolder);
picHolder.x = 0;
picHolder.y = 0;
}
private function loadImages():void {
resultText.text = " Starting to load images";
loader.add(imageURL, {type:BulkLoader.TYPE_IMAGE}); // explicitly declare the type
//loader.add(imageURL, {id:"bg"}); // or use ID
loader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
loader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress);
loader.addEventListener(BulkLoader.ERROR, onAllError);
// now start the loading
loader.start();
}
]]>
</fx:Script>
mx:HBox
mx:VBox
<mx:Canvas id="mainCanvas" height="300" width="900" borderStyle="solid" backgroundColor="0xFFFFFC">
/mx:Canvas
mx:HBox
<mx:TextArea id="errorText" text="Errors Go Here" width="200" >
/mx:TextArea
<mx:TextArea id="progressText" text="Progress Goes Here" width="200">
/mx:TextArea
<mx:TextArea id="resultText" text="Result Goes Here" width="200">
/mx:TextArea
/mx:HBox
/mx:VBox
/mx:HBox
/s:Application