Flash AS3 Scratch Off Class

flash as3 lottery scratcher class for free
Flash AS3 lottery scratcher class for free!

Lottery ticket scratcher effect in AS3

Here is a really sharp ActionScript 3 class that creates a quick way to make a fun promotional or interactive scratch off effect.

Much like the rub off effect used on lottery tickets and sweepstakes, with this class you can add in your image and then have your website visitors interact with the page to reveal the hidden message, image, video, link, or promotion that is underneath.

Oh, did we mention it was free? Thanks to our pals at immortalwolf.com it is!

Here is the simple to understand source code:

// ScratchOff.as
// immortalwolf scratch off
// immortalwolf.com
package com.immortalwolf{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.ui.Mouse;

public class ScratchOff extends MovieClip{
var scratcherIsActive:Boolean= false;
var stuffUnderMask:Sprite = new Sprite();

// init class
public function ScratchOff():void{
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseIsDown);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseIsMoving);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseIsUp);
// make mask
stuffUnderMaskClip.mask = stuffUnderMask;

// helper functions
private function makeCursor():void{
trace("you can make a special cursor and hide it!");
// hover effects
private function mouseIsDown(e:MouseEvent):void{
scratcherIsActive = true;
private function mouseIsUp(e:MouseEvent):void{
scratcherIsActive = false;
private function mouseIsMoving(e:MouseEvent):void{
stuffUnderMask.graphics.drawEllipse(mouseX, mouseY,40, 40);
}// class
}// package


[kml_flashembed publishmethod=”static” fversion=”9.0.0″ movie=”/wp-content/uploads/2010/11/ScratchOff.swf” width=”590″ height=”342″ targetclass=”flashmovie” play=”true” menu=”false” quality=”high” scale=”showall” wmode=”opaque” swliveconnect=”true” allowfullscreen=”false” allowscriptaccess=”sameDomain” base=”/wp-content/uploads/2010/11/”]

Get Adobe Flash player


Pretty straightforward huh? But fun also!

The shape of the element getting scratched off doesn’t have to be a circle by the way – so get creative!

Don’t forget the download:

Download Flash AS3 Scratch Off Class

Support and questions

Please direct any inquiries for this file in the comments below.