when run my android app ( creat by flash cs6 as3 ) error :
this is first code in first frame :
and this is main code in frame 2 :
when I hear the camera shot sound, the error is shown. tanx for help .
my app detects the camera and shot !An error has occurred in sub: settingm_camera1_ready (java line: 464) java.lang.IllegalStateException:The specified child already has a parent.you must call removeView() on the child s parent first.
this is first code in first frame :
Code:
stop();
rec_btn.addEventListener(MouseEvent.CLICK, mouseHandler);
function mouseHandler5(event:MouseEvent):void
{
gotoAndPlay("stop");
}
videoDetect.attachCamera(null);
videoCapture.attachCamera(null);
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
and this is main code in frame 2 :
Code:
import flash.media.Video;
import flash.media.Camera;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.BlendMode;
import flash.filters.ColorMatrixFilter;
import flash.geom.Matrix;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.filters.BlurFilter;
import flash.display.Graphics;
import flash.events.Event;
import flash.display.PixelSnapping;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import com.adobe.protocols.dict.Database;
import com.adobe.images.PNGEncoder;
import flash.filesystem.FileMode;
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
/* INIT VARIABLES */
var timeoutTimerTime:uint = 1500;
var detectWidth:uint = 260;
var detectHeight:uint = 202;
var captureWidth:uint = 800;
var captureHeight:uint = 600;
var minMotionWidth:uint = 20;
var savePath:String = "DCIM/";
/* INIT VIDEOS AND CAMERAS */
var camera:Camera = Camera.getCamera();
camera.setMode(detectWidth, detectHeight, stage.frameRate);
var videoDetect:Video = new Video(detectWidth, detectHeight);
videoDetect.attachCamera(camera);
var captureCamera:Camera = Camera.getCamera();
captureCamera.setMode(captureWidth, captureHeight, 24);
var videoCapture:Video = new Video(captureWidth, captureHeight);
videoCapture.attachCamera(captureCamera);
/* INIT BITMAPS */
var matrix:Array = new Array();
matrix = matrix.concat([9, 0, 0, 0, -255]);
matrix = matrix.concat([0, 9, 0, 0, -255]);
matrix = matrix.concat([0, 0, 9, 0, -255]);
matrix = matrix.concat([0, 0, 0, 1, 0]);
var colorMatrixFilter:ColorMatrixFilter = new ColorMatrixFilter();
colorMatrixFilter.matrix = matrix;
var point:Point = new Point(0, 0);
var bitmapData0:BitmapData = new BitmapData(detectWidth, detectHeight, false,0 );
var bitmapData1:BitmapData = new BitmapData(detectWidth, detectHeight, false, 0);
var bitmapData2:BitmapData = new BitmapData(detectWidth, detectHeight, false, 0);
var bitmap0:Bitmap = new Bitmap(bitmapData0);
var bitmap1:Bitmap = new Bitmap(bitmapData1);
bitmap1.blendMode = BlendMode.DIFFERENCE;
var bitmap2:Bitmap = new Bitmap(bitmapData2);
var container:Sprite = new Sprite();
container.filters = [new BlurFilter(2, 2), colorMatrixFilter];
container.addChild(bitmap0);
container.addChild(bitmap1);
var canvas:Sprite = new Sprite();
/* DISPLAY */
container.x = 226 ;
container.y = 184;
canvas.x = 226;
canvas.y = 184;
addChild(container);
addChild(canvas);
/* TIMER FUNCTIONS */
var rectangle:Rectangle;
var imageTimer:Timer;
var canvasGraphics:Graphics = canvas.graphics;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(pEvent:Event):void
{
bitmapData0.draw(bitmapData1);
bitmapData1.draw(videoDetect);
bitmapData2.draw(container);
rectangle = bitmapData2.getColorBoundsRect(0xffffff, 0x000000, false);
if(rectangle.width > minMotionWidth && rectangle.height > minMotionWidth)
{
canvasGraphics.clear();
canvasGraphics.lineStyle(0, 0xffffff, 1);
canvasGraphics.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
canvasGraphics.endFill();
createImage();
}
}
/* CREATE IMAGE FUNCTIONS */
var time:String;
var date:Date;
var byteArray:ByteArray;
var file:File;
var fileStream:FileStream;
var hasTimeout:Boolean;
var videoDetectBitmapData:BitmapData;
var timeoutTimer:Timer = new Timer(timeoutTimerTime);
timeoutTimer.addEventListener(TimerEvent.TIMER, timeoutTimerTimerHandler);
function timeoutTimerTimerHandler(e:TimerEvent):void
{
hasTimeout = false;
}
function createImage():void
{
if(!hasTimeout)
{
date = new Date();
time = String(date.fullYear).slice(-2) + ("00" + String(date.month + 1)).slice(-2) + ("00" + String(date.day)).slice(-2) + ("00" + String(date.hours)).slice(-2) + ("00" + String(date.minutes)).slice(-2) + ("00" + String(date.seconds)).slice(-2);
videoDetectBitmapData = new BitmapData(captureWidth, captureHeight);
videoDetectBitmapData.draw(videoCapture);
byteArray = PNGEncoder.encode(videoDetectBitmapData);
file = File.desktopDirectory.resolvePath(savePath + time + ".png");
fileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(byteArray);
fileStream.close();
}
hasTimeout = true;
timeoutTimer.start();
}