views:

189

answers:

2

Hi there,

I am a total Flash newbie. I just installed Flash CS5 and wrote the following 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);
}

On exporting to SWF, I am getting the error :

The class or interface com.adobe.images.JPGEncoder could not be loaded

I have downloaded the as3corelibrary from the right source from code.google.com and have placed the folder in the root. Right now it is C:\wamp\www\com\adobe\images\JPGEncoder.as

Is there some classpath or something that I have to set ?

A: 

Yes you need to set the classpath.

From Adobe help:

To set the application-level source path:

  1. Choose Edit Preferences (Windows) or Flash > Preferences (Macintosh) and click the ActionScript category.
  2. Click the ActionScript 3.0 Settings button and add the path(s) to the Source path list.
nikc
You mean add "C:\wamp\www\com\adobe\images\JPGEncoder.as" or just "C:\wamp\www\com\adobe\images" ?
Hrishikesh Choudhari
You should add `C:\wamp\www`. The package `com.adobe.images` tells the compiler where to look for the classes.
nikc
A: 

Looks like you've put the code for as3corelib in the root of the web server - you've to put the source in the root folder of your source path. Normally that's the same folder that has your FLA. Copy the com folder to the same folder that contains your FLA and then compile.

In case you've your FLA in the same folder (the root of the web server), that's a bad idea to begin with - everybody will be able to access your source code.

Amarghosh
Oh yes I did put the as3corelib in my server's root. And the FLA file is somewhere else. I'll correct myself as you said.
Hrishikesh Choudhari