0

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 ?

Simon Hayter
  • 3,131
  • 27
  • 53
LovelyHanibal
  • 317
  • 2
  • 13
  • are you testing on a server or locally? If locally, try running the app from a server using chrome – Ronnie Dec 12 '12 at 01:03
  • I was testing on localfiles. – LovelyHanibal Dec 12 '12 at 01:40
  • I didn't suspect that it will make different. But now when I put it to server then it work. Thank you for your help. Do you know is it normal acting of chrome, or am I doing something wrong so it work only at server ? – LovelyHanibal Dec 12 '12 at 01:42
  • @LovelyHanibal you're likely running into a security error, possibly due to cross domain problems that weren't being seen in Chrome because it manages it's own flash player plugin and Google pushes updates in the background. You can disable the built in Flash player and have it fall back on the Netscape-plugin compatible debug player. Do a search for the details. – shaunhusain Dec 12 '12 at 02:07
  • Ronnie, you basically answer my question. If you put it as answer I will approve it.
    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
  • @LovelyHanibal Unfortunately (cause I really like AS3) the bad news is it won't work in modern browsers today on mobile devices (in general). I don't expect that desktop Flash will evaporate immediately, desktop is still ~90% of the traffic http://webdesignersmn.com/feature-web-design/important-business-owners-pay-attention.html/ http://mitchspeers.com/2011/07/23/ipad-nirvana-for-b2b-media-get-serious/ I see no reason Adobe would abandon Flash on Desktops but you may want to consider AIR for mobile deployment too, or other solutions for a longer term reach. – shaunhusain Dec 12 '12 at 02:41
  • little trics for you, use [fiddler's](http://www.fiddler2.com/fiddler2/) autoresponder for the localtesting. Change in your html code swf url to "real" server address, add rule in fiddler autoresponder and testing your applet localy. – Pavel Shirobok Dec 12 '12 at 04:33
  • @LovelyHanibal please do not use swear words in any content that you post on StackOverflow. Your question will be edited to remove the swearing. – Jason Evans Jan 31 '13 at 20:36

1 Answers1

2

I've had issues loading flash content locally in chrome. Its the flash global player settings. The problem is, chrome has its own version of flash built in..I forget what its called..I think pepper flash? Anyway, it doesn't obey the settings all the time from this site: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

As long as you are testing on a web server it should be fine..heck even a local web server will work

Ronnie
  • 11,138
  • 21
  • 78
  • 140
  • 1
    to add to this, additionally you can disable pepper flash by typing `chrome://plugins/` in the address bar. Next, click the +Details and find pepper flash and disable it. As long as you have the plugin version installed it will work – Ronnie Jan 31 '13 at 21:07