hi to all,
i have a image loader that bypasses the crossdomain.xml to load images from other server.
on windows 7/8 it work´s fine. but on osx the “LoaderInfo(event.target).bytes” throws me “null”. can´t figure out if it´s possible to fix - so maybe someone has an hint for me, please.
package com.marek{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.system.LoaderContext;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.*;
import flash.errors.*;
import com.greensock.TweenLite;
import flash.events.IOErrorEvent;
public class imgLoader extends Sprite {
private var loader:Loader = new Loader();
private var lInfo:LoaderInfo;
private var dO:DisplayObject;
private var thumbW:Number = 170;
private var thumbH:Number = 170;
private var context:LoaderContext = new LoaderContext(true);
public function imgLoader(iPath:String) {
loader.contentLoaderInfo.addEventListener(Event.INIT, _init);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _complete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,_ioerror);
loader.load(new URLRequest(iPath), context);
}
protected function _init(event:Event):void {
lInfo = event.target as LoaderInfo;
try {
dO = lInfo.loader.content;
} catch (err:SecurityError) {
var s:Sprite = new Sprite();
s.addChild(lInfo.loader);
dO = s as DisplayObject;
}
}
protected function _complete(event:Event):void {
var ba:ByteArray = LoaderInfo(event.target).bytes;
_reloadByteArray(ba);
}
protected function _reloadByteArray(ba:ByteArray):void {
var reloader:Loader = new Loader();
reloader.loadBytes(ba);
reloader.contentLoaderInfo.addEventListener(Event.COMPLETE, _rbaComplete);
}
protected function _rbaComplete(event:Event):void {
var imgInfo:LoaderInfo = LoaderInfo(event.target);
var bmd:BitmapData = new BitmapData(imgInfo.width,imgInfo.height);
bmd.draw(imgInfo.loader);
var imgBMP:Bitmap = new Bitmap(bmd);
imgBMP.smoothing = true;
var sx:Number = thumbW / imgInfo.width;
var sy:Number = thumbH / imgInfo.height;
sx = Math.max(sx, sy);
if (sx > 1) {
imgBMP.x = -(imgBMP.width - thumbW) / 2;
imgBMP.y = -(imgBMP.height - thumbH) / 2;
} else {
imgBMP.scaleX *= sx;
imgBMP.scaleY *= sx;
imgBMP.x = -(imgBMP.width - thumbW) / 2
}
this.addChild(imgBMP);
TweenLite.from(imgBMP, 1, {alpha:0});
}
private function _ioerror(event:Event):void {
var blank:Class = getDefinitionByName("image_blank") as Class;
var blankimg:Bitmap = new Bitmap(new blank());
blankimg.x = -(blankimg.width - thumbW) / 2;
blankimg.y = -(blankimg.height - thumbH) / 2;
this.addChild(blankimg);
}
}
}
thx - greets marek from berlin