Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T
Accepted Solution

Anyone used CameraRoll yet? Seems completely broken.

I'm trying to implement browsing for a file using the CameraRoll since the File.Browse() methods are still badly broken. I've implemented a load method using the example from the docs. Sadly, it seems to simply crash the application. Here's the code so far.

 

private function load(e:MouseEvent):void
{
	trace("loading");
	menu.close();
	if( CameraRoll.supportsBrowseForImage )
	{
		var mediaSource:CameraRoll = new CameraRoll();

		mediaSource.addEventListener( MediaEvent.SELECT, imageSelected );
		
		mediaSource.browseForImage();
	}
	else
	{
		var myFile:File = File.documentsDirectory;
		var filter:FileFilter = new FileFilter("Images", "*.png;*.jpg")
		myFile.browse( [filter]);
		myFile.addEventListener(Event.SELECT,chooseFile);
	}
}

private function imageSelected( e:MediaEvent ):void
{
	trace(e.target.nativePath);
	img.setImage(e.target.url);
}

private function chooseFile(e:Event):void
{
	trace(e.target.nativePath);
	trace(e.target.name);
	var name2:File = File.desktopDirectory.resolvePath(e.target.name);
	trace(name2.nativePath);

	img.setImage(name2.url);
}		

 

 

i'm detecting to see if the camera roll is supported, and then using one of two callback methods to load the file.  It could be done with one callback method if we could rely on the event.Target property from the File.Browse method, but we can't and that's another problem. 

 

Anyway, it seems very straight-forward. When it runs in the sim, the supportsBrowseForImage property is true indicating it is supported, but when calling browseForImage(), the app just disappears. The callback is never called. I think i can actually see a gray bar at the bottom as if the app were minimized, but I can't bring it back. Heck, I can't even bring up the system menu. If I redeploy the app (which causes the previous one to be uninstalled) it seems to recover.

 

I'm using FB Burrito and I'm changed the project settings to use the .94 SDK. I'm using the .94 simulator.

 

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Highlighted
Developer
Posts: 133
Registered: ‎12-02-2010
My Device: Z10 & Dev Alpha C
My Carrier: T

Re: Anyone used CameraRoll yet? Seems completely broken.

I installed TourDeMobileFlex Found here: http://flex.org/TourDeMobileFlex.fxp

 

The camera roll of TourDeMobileFlex seems to be working just fine in the 0.9.4 simulator. It opens the roll and you can pick your previously saved image.

 

Code of the CameraRoll from the TourDeMobileFlex:

 

<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
     paddingTop="10">

    <s:Button label="Pick a Photo from the Roll">
        <s:click>
            if (CameraRoll.supportsBrowseForImage)
            {
                var cameraRoll:CameraRoll = new CameraRoll();
                cameraRoll.addEventListener(MediaEvent.SELECT, function(event:MediaEvent):void {
                    i.source = event.data.file.url;
                });    
                cameraRoll.browseForImage();
            }
            else
            {
                l.text = "CameraRoll not supported";
            }
        </s:click>
    </s:Button>
    
    <s:Button label="Add a Photo to the Roll">
        <s:click>
            if (CameraRoll.supportsAddBitmapData)
            {
                var cameraRoll:CameraRoll = new CameraRoll();
                var bd:BitmapData = new BitmapData(640, 480);
                bd.perlinNoise(640, 480, 1, Math.floor(Math.random() * 10), false, true);
                i.source = bd;
                cameraRoll.addBitmapData(bd);
            }
            else
            {
                l.text = "CameraRoll not supported";
            }
        </s:click>
    </s:Button>
    
    <s:Label id="l"/>
    
    <s:Image id="i" width="100%" height="100%"/>
    
</s:VGroup>

---------------------------------------------------------------------
Developer of Stocks for Blackberry 10
Developer
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T

Re: Anyone used CameraRoll yet? Seems completely broken.

Thanks for the sample code. I tried again and didn't see the odd behavior after doing a Clean. I think there was some funkiness with the build because I had also just switched from .93 to .94 SDK.  Once I did a clean and retested, it worked, but I found that the code in my handler was wrong, so I appreciate your sample.

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids