When I open a text document containing 1 string of a Base64 Encoded Image, it works fine:
import flash.display.Loader;
import flash.utils.ByteArray;
import formatter.Base64;
var imgB64Str:String="";
var ld:Loader=new Loader();
var my_req:URLRequest = new URLRequest("horses.img");
var my_loader:URLLoader = new URLLoader();
my_loader.addEventListener(Event.COMPLETE, loadText);
my_loader.load(my_req);
function loadText(e:Event):void{
// set string variable to loaded text
imgB64Str = my_loader.data;
// position, decode & display
ld.x = ld.y = 50;
ld.loadBytes(Base64.Decode(imgB64Str));
addChild(ld);
}
The image displays and that’s great, but I need to display multiple images; therefore, I used the standard format: var1=value1&var2=value2&…
(In reality, the values are the huge base64 strings.)
Then I just needed to add “my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;” since the format of my source changed.
The thing that bugs me is that I’m tracing the imgB64Str after I set it and it traces fine (just like the other version). And from then on I’m not doing anything different!
See my comments for things I did different…
import flash.display.Loader;
import flash.utils.ByteArray;
import formatter.Base64;
var imgB64Str:String="";
var ld:Loader=new Loader();
var my_req:URLRequest = new URLRequest("images.img"); // CHANGED: source file, due to new format
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES; // CHANGED: formatting input from text to variables
my_loader.addEventListener(Event.COMPLETE, loadText);
my_loader.load(my_req);
function loadText(e:Event):void{
imgB64Str = my_loader.data.image1; // CHANGED: instead of grabbing whole data, grabbing the image1 variable
trace(imgB64Str); // CHANGED: traces fine!
// same as other from here down!
ld.x = ld.y = 50;
ld.loadBytes(Base64.Decode(imgB64Str));
addChild(ld);
}
It runs with no errors, but the image no longer displays.
What’s the deal?!? :eek:
Any help is greatly appreciated.