-
Image Array references???
- Resolved -
Hi, I'm stuck on this one...
I'm having problems with the array (references?)
all pictures seem to change to the latest added (or) the retrieval aint working...
expl. code.
Some code for taking snapshots from webcam and store them in an array. A slideshow should show the pics from the array. A new snapshot should replace the old pic in the array[i].
I would very much appreciate code suggestions and help!
In the fla there's:
a movieclip "photoknapp" triggering the TakeSnapshot function
a movieclip "bildspel" for showing the slideshow.
//---------vars
var numberOfPics = 30;
var latestSnapShot = numberOfPics;
var latestShownPic = numberOfPics;
var kamx = 60;
var kamy = 30;
var kamw = 300;
var kamh = 480;
var fps = 8;
var bildspx = 500;
var bildspy = 30;
var picArray = new Array(numberOfPics);
var bitmap:Bitmap;
var bData:BitmapData;
// ------initiate array with "empty" bitmaps
for (var i= 0; i <numberOfPics; i++)
{
bData = new BitmapData(kamw,kamh,true,0x00000000);
bitmap = new Bitmap(bData);
picArray[i] = bitmap;
trace(i);
trace(picArray);
}
// ------Create camera and video flow
var webKamera:Camera = Camera.getCamera();
webKamera.setMode(kamw, kamh, fps,true );
var kameraStream:Video = new Video(kamw,kamh);
kameraStream.attachCamera(webKamera);
kameraStream.x = kamx;
kameraStream.y = kamy;
addChild(kameraStream);
// ---take and place picture in array
photoknapp.addEventListener(MouseEvent.CLICK,takeS napshot);
function takeSnapshot(e:MouseEvent):void
{
if (latestSnapShot==numberOfPics+1)
{
latestSnapShot = 0;
}
bitmapData.draw(kameraStream);
var bitmapData:BitmapData = new BitmapData(kamw,kamh);
var bild:Bitmap = new Bitmap(bitmapData);
picArray[latestSnapShot] = bild;
trace("pic taken");
latestSnapShot++;
}
//----slideshow
var myTimer:Timer = new Timer(3000); // 3 seconds
myTimer.addEventListener(TimerEvent.TIMER, ChangePic);
myTimer.start();
function ChangePic(event:TimerEvent):void
{
if (latestShownPic==numberOfPics+1)
{
latestShownPic = 0;
}
bildspel.addChild(picArray[latestShownPic])
trace(latestShownPic);
latestShownPic++;
}
Last edited by aqqaz; 05-28-2012 at 02:43 AM.
Reason: Resolved
-
Instead of making your code red, put it in [code] tags. That will make it readable and preserve formatting.
Code:
bitmapData.draw(kameraStream);
var bitmapData:BitmapData = new BitmapData(kamw,kamh);
Because of variable hoisting, that code will compile, but it should throw an error because bitmapData is null when you attempt to call its draw method. Swap the order of those two lines.
I don't see how you could get any actual images shown. Nothing should ever get set except in the initialization which sets them all to solid black.
Are you not getting errors? If you are getting errors, why didn't you tell us?
-
I'm sorry if didnt provide any information that was needed. I can see my error in not doing so and will do so next time. I'm fairly new in using forums. As you wrote there were an error thrown 'null reference', I thought I had misunderstood the Array handling.
Though, I'm very happy of your reply which solved my problem!
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|