Load External JPG into SWF on Android

I have my new HTC Desire Android phone for over a week now and I have been building little Flash apps here and there. Uisng the latest Flash CS5 with the AR 2.5 extension and the lab preview of Flash Builder, I found the experience very pleasant.

In my previous posts, I have talked about the new AS3 event models for mobile phones and how similar it is to the mouse events model. In this post I would like to show how to load external photos sitting in the SD card into a mobile Flash apps running on Android 2.2. Try the code below:

import flash.filesystem.File;

var fileChooser:File = File.userDirectory;

fileChooser.addEventListener(Event.SELECT, doSelect);

function doSelect(e:Event):void
{

var pic:Loader = new Loader();
pic.load(new URLRequest(e.target.url));
addChild(pic);

}

fileChooser.browseForOpen(“Open”);

 

As you can see from above, the code is exactly like what you would expect for a standard AIR app. Again, you can also add FileFilter to limit to file types to be displayed on the file dialog box. Of course, there are differences between developing desktop vs mobile apps. But your AS3 skills can help a long way in building Android and iOS apps.

Advertisements

~ by brianchau on February 2, 2011.

3 Responses to “Load External JPG into SWF on Android”

  1. Hi Brian, my name is Dan i have just got adobe flash cs5 with air addon and also have flash builder. i have been looking everywhere for a little help on building an app for android but have had no such luck. is there any chance you could help me or direct me to somewhere that can help please. i look forward to hearing from you. danwood84@hotmail.com

  2. Hi Brian,
    Great post, thanks. I’m trying to do something like that. My flash file works and I’m able to load external images, but when I export it as Android app through Flash, the app doesn’t load the external images at all, even if I gave it all the possible permission (including of course “internet”).
    Please, do you have any suggestion?
    Thanks a lot,
    Alberto

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: