about1

This CAPTCHA Class uses Securimage. You can get it here

Securimage is an open-source free PHP CAPTCHA script for generating complex images and CAPTCHA codes to protect forms from spam and abuse…

show.php

 php |  copy |? 
1
2
include 'securimage.php';
3
$img = new securimage();
4
$img->show();
5

To load the created image, just write an URLLoader than a Loader, that loads the URLLoader data ….

Captcha.as

 as3 |  copy |? 
01
02
 public class Captcha extends Sprite
03
 {
04
 private var _loader:URLLoader;
05
 private var _captchadata:BitmapData;
06
 private var _captcha:Bitmap;
07
 private var _cont:Sprite;
08
09
 public function Captcha()
10
 {
11
 this._cont = new Sprite();
12
 this._cont.useHandCursor = true;
13
 this._cont.buttonMode = true;
14
15
 this._loader = new URLLoader();
16
 this._loader.dataFormat = URLLoaderDataFormat.BINARY;
17
 var url:String = "show.php";
18
 var urlReq:URLRequest = new URLRequest(url);
19
20
 this._loader.addEventListener(Event.COMPLETE, completeHandler);
21
 this._loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
22
 this._loader.load(new URLRequest(url));
23
 }
24
 private function ioErrorHandler(e:IOErrorEvent):void
25
 {
26
 //SOS.alert(_e.toString());
27
 }
28
 private function completeHandler(e:Event):void 
29
 {
30
 this._loader.removeEventListener(Event.COMPLETE, completeHandler);
31
 this._loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
32
33
 var myLoader:Loader = new Loader();
34
 myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, createCaptcha);
35
   
36
 var byteArr:ByteArray = new ByteArray();
37
 byteArr = this._loader.data;
38
39
 if(byteArr.length != 0) { myLoader.loadBytes(this._loader.data); } 
40
 else { /* SOS.alert("error"); */ }
41
 }
42
 private function createCaptcha(e:Event):void
43
 {
44
 this._captchadata = new BitmapData(175, 45, false, 0xFFFFFF); //sizes of secureimage.php ~ Line 89
45
 this._captchadata = (e.target.content).bitmapData;
46
47
 this._captcha = new Bitmap(this._captchadata, "auto", true);
48
 this._captcha.x = 920;
49
 this._captcha.y = 92;
50
 this._cont.addChild(this._captcha);
51
 this._cont.addEventListener(MouseEvent.MOUSE_DOWN , renew);
52
 this.addChildAt(this._cont,0);
53
 }
54
 private function renew(_me:MouseEvent):void
55
 {
56
 this._cont.removeChildAt(0);
57
 var url:String = "show.php?"+Math.random()*100;
58
 var urlReq:URLRequest = new URLRequest(url);
59
60
 this._loader.addEventListener(Event.COMPLETE, completeHandler);
61
 this._loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
62
 this._loader.load(new URLRequest(url));
63
64
 }
65
 }
66

I hard-coded some dimensions inside the class, and some other ugly things, so feel free to change for your needs.
But don’t forget to put the Math.random() after the URI to refresh the captcha, this can avoid caching issues.
You can see this class Working here. Click on the share Btn.

Sure, this class can be used to load nearly all types of binary image data ….

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png