0
import flash.media.CameraRoll;
import flash.display.Loader;
import flash.media.MediaPromise;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MediaEvent;
import flash.events.Event;

backbtn6.addEventListener(MouseEvent.CLICK, back);

var cameraroll:CameraRoll;
var loader:Loader;
var promise:MediaPromise;
var bitmap:Bitmap;
var bitmapdata:BitmapData;

openpic.addEventListener(MouseEvent.CLICK, selectpic);
function selectpic(e:MouseEvent):void
{
if(CameraRoll.supportsBrowseForImage)
{
    cameraroll = new CameraRoll();
    cameraroll.addEventListener(MediaEvent.SELECT, loadpic);
    cameraroll.browseForImage();
}

}

function loadpic(e:MediaEvent):void
{
promise = e.data as MediaPromise;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showpic);
loader.loadFilePromise(promise);
}

function showpic(e:Event):void
{
if(bitmap != null)
{
    removeChild(bitmap);
}

var originalWidth:int = Bitmap(e.currentTarget.content).width;
var originalHeight:int = Bitmap(e.currentTarget.content).height;

bitmapdata = new BitmapData(originalWidth,originalHeight);
bitmap = new Bitmap(bitmapdata);
bitmap.bitmapData = Bitmap(e.currentTarget.content).bitmapData;

bitmap.x = 0;
bitmap.y = 0;

addChild(bitmap);
}

it's my as3 code for android using AIR. I wrote down this code seeing ather people's code. but it's not working in my android phone. what's the metter with my code...help me.. how can I do??

If yoy have any solutions, Its my pleasure for developing. I'm just one month studying as3

1 Answers1

0

With the few details mentioned in your questions, I think this is a problem of permissions and the code is fine. Try to add this permission :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

You can add it directly to your your_app-app.xml, where your_app is the name of your application ( project ), before </application> like this :

<application xmlns="http://ns.adobe.com/air/application/15.0">

    <!-- ... -->

    <android>
        <manifestAdditions>
            <![CDATA[<manifest>
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
            </manifest>]]>
        </manifestAdditions>
    </android>
</application>

Of course, don't touch the other content of your XML, you have just to add ( or edit if already exist ) the part <android>...</android>.

Or simply using AIR xxx for Android Settings dialog, where xxx is the version of AIR, accessible from the File menu, then go to Permissions tab and select the WRITE_EXTERNAL_STORAGE permission like this ( of course this is for Flash ) :

enter image description here

If you still always got nothing, try to add an ErrorEvent event listener to your CameraRoll object to catch errors :

cameraroll.addEventListener(
    ErrorEvent.ERROR, 
    function(e:ErrorEvent):void { 
        log.text = e.text;
    }
)

Hope that can help.

akmozo
  • 9,671
  • 3
  • 24
  • 38