我正在尝试编写闪存小程序,用户可以在其中从硬盘上传图像。
所以actionscript将编辑图像并将其发送到服务器。
加载图像在 flash player、firefox 和 opera 中工作,但在 chrome 中选择图像后它会停止。
我正在使用flashdevelop。
这是我的代码:
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);
});
}
}
是不是因为 chrome 的某些限制(我读到 chrome 中的 flash 在沙箱中)?
有没有更好的方法来做到这一点?