views:

30

answers:

1

Hi there..

I am a total Flash newbie. I just installed Flash CS5 and ran this code.

import flash.display.BitmapData
import flash.geom.Matrix
import com.adobe.images.JPGEncoder;
import flash.net.FileReference;
import flash.utils.ByteArray;

//get the default camera
//change your Default camera using the Flash Player Settings.
cam=Camera.get()
//this event is called whenever permission to access the local camera, is accepted or denied by the user
cam.onStatus=function(e)
{
    //if we are given permission
    if(e.code == "Camera.Unmuted")
    {
        //start the application
        initialize()
    }
    else
    {
        System.showSettings(3)
    }
}

var snapshot:BitmapData=new BitmapData(cam.width,cam.height);

function takeSnapshot()
{   
    var i:Number=1;
    var fileRef:FileReference = new FileReference();
    snapshot.draw(cam,new Matrix());
    //saveImage();
     var encoder:JPGEncoder = new JPGEncoder();
     var ba:ByteArray = encoder.encode(bitmapData);
     fileRef.save(ba,"capture"+i+".jpg");
     i++;
}


//if there are no Cameras
if(cam == null)
{
    System.showSettings(3)
}
else
{
    cam.setMode(1024, 768, 30);
    cam.setQuality(10000,0);
    output.attachVideo(cam);
    setInterval(this,"takeSnapshot",100);
}

Then on exporting to SWF I get the error: The class or interface 'flash.utils.ByteArray' could not be loaded.

Any help here ?

Are there any AS3 settings I need to change ?

A: 

Sounds like you're not exporting using AS3, when you got to export be sure to select "Actionscript 3" as the language. I just tried it using CS3 (but I doubt CS5 changed anything in this regard), and everything worked fine.

To change a project to AS3 (in CS3): Go to File > Publish Settings... > Click the flash tab > Change ActionScript version to "Actionscript 3.0".

sdolan
In the publish settings, I dont get AS3 in the drop down menu. Only AS1 and AS2 are available. This seems baffling.
Hrishikesh Choudhari
@Hrishikesh Choudhari: I figured that would be it. I just updated my answer to have the steps to change it on the project level. I tested creating an AS2 project then changing it to AS3 using the steps with success.
sdolan
@Hrishikesh Choudhari: are you targeting flash lite or flash 8 and below?
back2dos
Hi sdolan, Thanks for the tips but there's no AS3 in the drop down menu. As you said, in the 'Flash' tab, change to AS3, but to me, only AS1 and AS2 are available.
Hrishikesh Choudhari
@Hrishikesh Choudhari: As I said I only have CS3, and I may have setup things bit differently in my test. If you create a new AS3 project and add the bytearray import statement somewhere does that compile correctly?
sdolan