A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Image Array references???

  1. #1
    Junior Member
    Join Date
    Feb 2012

    resolved 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.

    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;

    // ------Create camera and video flow
    var webKamera:Camera = Camera.getCamera();
    webKamera.setMode(kamw, kamh, fps,true );
    var kameraStream:Video = new Video(kamw,kamh);
    kameraStream.x = kamx;
    kameraStream.y = kamy;

    // ---take and place picture in array

    photoknapp.addEventListener(MouseEvent.CLICK,takeS napshot);

    function takeSnapshot(e:MouseEvent):void
    if (latestSnapShot==numberOfPics+1)
    latestSnapShot = 0;
    var bitmapData:BitmapData = new BitmapData(kamw,kamh);
    var bild:Bitmap = new Bitmap(bitmapData);
    picArray[latestSnapShot] = bild;
    trace("pic taken");

    var myTimer:Timer = new Timer(3000); // 3 seconds
    myTimer.addEventListener(TimerEvent.TIMER, ChangePic);

    function ChangePic(event:TimerEvent):void
    if (latestShownPic==numberOfPics+1)
    latestShownPic = 0;
    Last edited by aqqaz; 05-28-2012 at 02:43 AM. Reason: Resolved

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Austin, TX
    Instead of making your code red, put it in [code] tags. That will make it readable and preserve formatting.
    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?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    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!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center