I'm trying to write flash applet where user can upload image from their hard disk.
So actionscript will edit image and send it to server.
Loading images work in flash player, firefox, and in opera, but in chrome after selecting image it stops.
I'm using flashdevelop.
Here is my code:
public class Main extends Sprite
{
[Embed(source = "../lib/lena.png")]
private var layer0Class : Class;
private var layer0:Bitmap = new layer0Class();
private var fileReferenceSelect:FileReference = new FileReference();
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
/// add image to flash scene
addChild(layer0);
/// add button
var my_button:SimpleButton;
my_button = new SimpleButton();
my_button.x = 150;
my_button.y = 50;
var cerchio:Shape=new Shape();
cerchio.graphics.beginFill(0x000000,1);
cerchio.graphics.drawCircle(my_button.x,my_button.y,20);
cerchio.graphics.endFill();
my_button.upState = cerchio;
my_button.overState = cerchio;;
my_button.downState=cerchio;
my_button.hitTestState = my_button.upState;
addChild(my_button);
/// button clicked
my_button.addEventListener(MouseEvent.CLICK,function(m:MouseEvent):void
{
fileReferenceSelect.browse([new FileFilter("PNG Files (*.png)","*.png; *.jpg; *.jpeg")]);
});
/// file selected
fileReferenceSelect.addEventListener(Event.SELECT, function(event:Event):void
{
fileReferenceSelect.load();
});
/// file ready to load
fileReferenceSelect.addEventListener(Event.COMPLETE, function(event:Event):void
{
var ldr:Loader = new Loader();
/// file loaded
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void {
var bm:Bitmap = Bitmap(e.target.content as Bitmap); /// here chrome is messing up
layer0.bitmapData = bm.bitmapData;
});
ldr.loadBytes(fileReferenceSelect.data);
});
}
}
Is it because of some limit in chrome (I read that flash in chrome is in sandbox) ?
Is there better way to do this ?
But still I will be happy to know if that code will work that way in any popular browser in next 5 years. – LovelyHanibal Dec 12 '12 at 02:14