Copy link to clipboard
Copied
HI, I am trying to compile my QR Code reader App using Adobe flash CS6, but keep getting the error "packages cannot be nested"
My code is as follows:
package
{
import com.logosware.event.QRdecoderEvent;
import com.logosware.event.QRreaderEvent;
import com.logosware.utils.QRcode.QRdecode;
import com.logosware.utils.QRcode.GetQRimage;
import net.hires.debug.Stats;
import com.bit101.components.*;
import flash.media.Sound;
import flash.display.*;
import flash.media.Camera;
import flash.media.Video;
import flash.events.*;
import flash.utils.Timer;
import flash.desktop.NativeApplication;
import flash.geom.Rectangle;
public class ReadQrSimple extends Sprite
{
private var detectionRate = 10;
private var getQRimage:GetQRimage;
private var qrDecode:QRdecode;
//string to save first decoded
private var qrDecodedDataOld:String;
private var cam:Camera;
private var video:Video;
private var markerArea;
private var markerAreaRect:Rectangle;
var holder:Holder = new Holder();
private var markerGuide:Sprite;
private var txt:TextArea;
private var refreshTimer:Timer;
private var timesCompleted = 0;
private var btnclear:BtnClear = new BtnClear();
private var quit:Quit = new Quit();
var snd:Sound = new camerasound();
var readSuccess:Number = 0;
public function ReadQrSimple():void
{
displayDebugText();
// initialize the webcam
cam = Camera.getCamera();
if(cam != null)
{
cam.setMode(320,240,30);
video = new Video(cam.width, cam.height);
holder.x = 240;
holder.y = 290;
holder.rotation = 90;
holder.scaleX = 1.3;
holder.scaleY = 1.3;
addChild(holder);
video.attachCamera(cam);
video.x = -160;
video.y = -120;
video.scaleX = 1;
video.scaleY = 1;
holder.addChild(video);
btnclear.x= 70;
btnclear.y = 770;
addChild(btnclear);
btnclear.buttonMode = true;
btnclear.addEventListener(MouseEvent.CLICK, onClear);
quit.x= 250;
quit.y = 770;
addChild(quit);
quit.buttonMode = true;
quit.addEventListener(MouseEvent.CLICK, QuitApplication);
markerArea = 200;
markerAreaRect = new Rectangle((cam.width-markerArea)/2,(cam.height-markerArea)/2,markerArea,markerArea);
getQRimage = new GetQRimage(video);
// run onQrImageReadComplete when the QR Code is found
getQRimage.addEventListener(QRreaderEvent.QR_IMAGE_READ_COMPLETE, onQrImageReadComplete);
// setup QRdecoder object
qrDecode = new QRdecode();
// invoked when QR Code is found
qrDecode.addEventListener(QRdecoderEvent.QR_DECODE_COMPLETE, onQrDecodeComplete);
// check the image n times a second (n = detectionRate)
refreshTimer = new Timer(1000/detectionRate);
refreshTimer.addEventListener(TimerEvent.TIMER, refresh);
refreshTimer.start();
}
else
{ txt.text = "Didn't find a webcam\n";
}
// display a guide where to put the marker
displayMarkerGuide();
// add Mr. Doobs Hi-ReS! stats
//addChild( new Stats() );
}
function onClear(event:MouseEvent):void{
trace("clear");
myQRText.text = " ";
readSuccess = 0;
}
private function refresh( event:Event ):void
{ // process webcam image and check for QRcode
getQRimage.process();
}
private function onQrImageReadComplete(e:QRreaderEvent):void
{
qrDecode.setQR(e.data);
qrDecode.startDecode();
}
private function onQrDecodeComplete(e:QRdecoderEvent):void
{ // e.data is the string decoded from QR Code
timesCompleted++; // number times of recognition since start of program
var decodedDataNew = e.data;
var compare = decodedDataNew.localeCompare(qrDecodedDataOld);
if(compare==0 && readSuccess == 0)
{ txt.text = String(timesCompleted)+"\t data: "+e.data+"\n"+txt.text;
snd.play();
myQRText.text = String(e.data);
readSuccess = 1;
}
else
{ txt.text = String(timesCompleted)+"\t ERROR \n"+txt.text;
}
qrDecodedDataOld = decodedDataNew;
}
private function displayMarkerGuide():void
{ markerGuide = new Sprite();
var guideLW:int = 5;
var guideColor:uint = 0xFFFFFF;
// make the MarkerGuide smaller than the markerArea
// in this case users don't have to put the marker that precise in the area for detection
var mRect = markerAreaRect;
mRect.inflate(-40,-40)
with(markerGuide.graphics)
{ lineStyle(guideLW, guideColor, 1, false, LineScaleMode.NONE, CapsStyle.SQUARE, JointStyle.MITER);
drawRect(mRect.x,mRect.y,mRect.width,mRect.height);
lineStyle();
beginFill(guideColor);
drawRect(mRect.x,mRect.y,10,10);
drawRect(mRect.x+mRect.width-(guideLW*2), mRect.y,10,10);
drawRect(mRect.x, mRect.y+mRect.height-(guideLW*2),10,10);
endFill();
}
markerGuide.alpha = 0.7;
markerGuide.scaleX = 2.6;
markerGuide.scaleY = 2.0;
markerGuide.x = -420;
markerGuide.y = -240;
holder.addChild(markerGuide);
}
private function displayDebugText():void
{ txt = new TextArea();
txt.editable = false;
txt.width = stage.stageWidth-20;
txt.height = stage.stageHeight-700;
txt.x=10;
//txt.y=stage.stageHeight-txt.height-10;
txt.y=750;
//addChild(txt);
}
function QuitApplication(e:Event):void
{
trace("quit");
holder.removeChild(video);
cam = null;
NativeApplication.nativeApplication.exit();
}
}
}
IS THERE ANY ONE THAT CAN HELP, AS I AM NOT SURE WHERE I HAVE GONE WRONG!?!?
Thanks
Errol
Copy link to clipboard
Copied
there are no nested packages in that code.
search your class path(s) for another class file with the same name.
p.s. stop posting to the other thread with the duplicate post.
Copy link to clipboard
Copied
Are you writing this code on timeline in a frame or is it a distinct .as file?
If you you write this code on the timeline - you cannot do that. You must create separate .as files for every class.