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;
			addChild(stuffUnderMask);
			makeCursor();
		}
		
		// helper functions
		private function makeCursor():void{			
			trace("you can make a special cursor and hide it!");
		}
		// hover effects
		private function mouseIsDown(e:MouseEvent):void{
			//Mouse.hide();
			Mouse.cursor="hand";
			scratcherIsActive = true;
		}
		private function mouseIsUp(e:MouseEvent):void{
			//Mouse.show();
			Mouse.cursor="arrow";
			scratcherIsActive = false;
		}
		private function mouseIsMoving(e:MouseEvent):void{
			if(scratcherIsActive){
				stuffUnderMask.graphics.beginFill(0x000000);
				stuffUnderMask.graphics.drawEllipse(mouseX, mouseY,40, 40);
				stuffUnderMask.graphics.endFill();
			}
		}
	}// class
}// package

Demo

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.

Related Posts
  • Pingback: richard()

  • Ricky

    I really appreciate if you post YouTube for this nice flash or depict step by step guide. I really like to learn and I;m beginners in Flash. Really appreciate. Thanks