Section 1
//BasicButton (BasicButton)
package {
import flash.display.*;
public dynamic class BasicButton extends SimpleButton {
}
}//package
Section 2
//Sound1 (Sound1)
package {
import flash.media.*;
public dynamic class Sound1 extends Sound {
}
}//package
Section 3
//WordSearch (WordSearch)
package {
import flash.events.*;
import flash.geom.*;
import flash.display.*;
import flash.media.*;
import flash.text.*;
public class WordSearch extends MovieClip {
public var progressText:TextField;
private var usedWords:Array;
private var dragMode:String;
public var startButton:SimpleButton;
private var letterSprites:Sprite;
private var gameSprite:Sprite;
public var beginButton:SimpleButton;
private var startPoint;
private var endPoint:Point;
public var progressText1:TextField;
private var grid:Array;
private var outlineSprite:Sprite;
private var numFound:int;
private var wordsSprite:Sprite;
private var wordList:Array;
var theSound1:Sound1;
public var playAgainButton:BasicButton;
private var oldOutlineSprite:Sprite;
static const outlineSize:Number = 28;
static const letterFormat:TextFormat = new TextFormat("Yikes!", 31, 0xFF00, true, false, false, null, null, TextFormatAlign.CENTER);
static const spacing:Number = 31;
static const offset:Point = new Point(27, 21);
static const puzzleSize:uint = 15;
public function WordSearch(){
theSound1 = new Sound1();
super();
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4, 4, frame5);
}
public function clickPlayAgain(_arg1:MouseEvent){
cleanUp();
gotoAndStop("play");
SoundMixer.stopAll();
}
public function clickBegin(_arg1:MouseEvent){
gotoAndStop("intro");
}
public function placeLetters():Array{
var _local1:Array;
var _local2:int;
var _local3:Array;
var _local4:int;
var _local5:int;
var _local6:int;
var _local7:String;
var _local8:int;
var _local9:int;
var _local10:int;
var _local11:String;
_local1 = new Array();
_local2 = 0;
while (_local2 < puzzleSize) {
_local1[_local2] = new Array();
_local5 = 0;
while (_local5 < puzzleSize) {
_local1[_local2][_local5] = "*";
_local5++;
};
_local2++;
};
_local3 = wordList.concat();
usedWords = new Array();
_local4 = 1000;
while (_local3.length > 0) {
var _temp1 = _local4;
_local4 = (_local4 - 1);
if (_temp1 <= 0){
break;
};
_local6 = Math.floor((Math.random() * _local3.length));
_local7 = _local3[_local6].toUpperCase();
_local2 = Math.floor((Math.random() * puzzleSize));
_local5 = Math.floor((Math.random() * puzzleSize));
_local8 = (Math.floor((Math.random() * 3)) - 1);
_local9 = (Math.floor((Math.random() * 3)) - 1);
if ((((_local8 == 0)) && ((_local9 == 0)))){
} else {
_local10 = 0;
while (_local10 < _local7.length) {
if (((((((((_local2 + (_local8 * _local10)) < 0)) || (((_local5 + (_local9 * _local10)) < 0)))) || (((_local2 + (_local8 * _local10)) >= puzzleSize)))) || (((_local5 + (_local9 * _local10)) >= puzzleSize)))){
//unresolved jump
};
_local11 = _local1[(_local2 + (_local8 * _local10))][(_local5 + (_local9 * _local10))];
if (((!((_local11 == "*"))) && (!((_local11 == _local7.charAt(_local10)))))){
//unresolved jump
};
_local10++;
};
_local10 = 0;
while (_local10 < _local7.length) {
_local1[(_local2 + (_local8 * _local10))][(_local5 + (_local9 * _local10))] = _local7.charAt(_local10);
_local10++;
};
_local3.splice(_local6, 1);
usedWords.push(_local7);
};
};
_local2 = 0;
while (_local2 < puzzleSize) {
_local5 = 0;
while (_local5 < puzzleSize) {
if (_local1[_local2][_local5] == "*"){
_local1[_local2][_local5] = String.fromCharCode((65 + Math.floor((Math.random() * 26))));
};
_local5++;
};
_local2++;
};
return (_local1);
}
public function overLetter(_arg1:MouseEvent){
if (dragMode == "drag"){
endPoint = findGridPoint(_arg1.currentTarget);
outlineSprite.graphics.clear();
if (isValidRange(startPoint, endPoint)){
drawOutline(outlineSprite, startPoint, endPoint, 0xFF00FF);
};
};
}
public function findGridPoint(_arg1:Object):Point{
var _local2:int;
var _local3:int;
_local2 = 0;
while (_local2 < puzzleSize) {
_local3 = 0;
while (_local3 < puzzleSize) {
if (grid[_local2][_local3] == _arg1){
return (new Point(_local2, _local3));
};
_local3++;
};
_local2++;
};
return (null);
}
public function checkWord(_arg1:String){
var _local2:int;
var _local3:String;
_local2 = 0;
while (_local2 < usedWords.length) {
if (_arg1 == usedWords[_local2].toUpperCase()){
foundWord(_arg1);
};
_local3 = _arg1.split("").reverse().join("");
if (_local3 == usedWords[_local2].toUpperCase()){
foundWord(_local3);
};
_local2++;
};
}
public function loadProgress(_arg1:Event){
var _local2:int;
var _local3:int;
var _local4:int;
var _local5:int;
_local2 = this.root.loaderInfo.bytesLoaded;
_local3 = this.root.loaderInfo.bytesTotal;
_local4 = (_local2 / 0x0400);
_local5 = (_local3 / 0x0400);
progressText.text = (((("Loading: " + _local4) + "K/") + _local5) + "K");
progressText1.text = (((("Loading: " + _local4) + "K/") + _local5) + "K");
if (_local2 >= _local3){
removeEventListener(Event.ENTER_FRAME, loadProgress);
gotoAndStop(2);
};
}
public function startWordSearch(){
var _local1:Array;
var _local2:int;
var _local3:int;
var _local4:int;
var _local5:TextField;
var _local6:Sprite;
var _local7:TextField;
wordList = "Red,Blue,Green,Yellow,Pink,Orange,Brown,Purple,Violet,Black,White,Gold,Mauve,Jade,Peach".split(",");
gameSprite = new Sprite();
addChild(gameSprite);
oldOutlineSprite = new Sprite();
gameSprite.addChild(oldOutlineSprite);
outlineSprite = new Sprite();
gameSprite.addChild(outlineSprite);
letterSprites = new Sprite();
gameSprite.addChild(letterSprites);
wordsSprite = new Sprite();
gameSprite.addChild(wordsSprite);
_local1 = placeLetters();
grid = new Array();
_local2 = 0;
while (_local2 < puzzleSize) {
grid[_local2] = new Array();
_local4 = 0;
while (_local4 < puzzleSize) {
_local5 = new TextField();
_local5.defaultTextFormat = letterFormat;
_local5.x = ((_local2 * spacing) + offset.x);
_local5.y = ((_local4 * spacing) + offset.y);
_local5.width = spacing;
_local5.height = spacing;
_local5.text = _local1[_local2][_local4];
_local5.selectable = false;
_local6 = new Sprite();
_local6.addChild(_local5);
letterSprites.addChild(_local6);
grid[_local2][_local4] = _local6;
_local6.addEventListener(MouseEvent.MOUSE_DOWN, clickLetter);
_local6.addEventListener(MouseEvent.MOUSE_OVER, overLetter);
_local4++;
};
_local2++;
};
stage.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);
_local3 = 0;
while (_local3 < usedWords.length) {
_local7 = new TextField();
_local7.defaultTextFormat = letterFormat;
_local7.x = 532;
_local7.y = ((_local3 * spacing) + offset.y);
_local7.width = 140;
_local7.height = spacing;
_local7.text = usedWords[_local3];
_local7.selectable = false;
wordsSprite.addChild(_local7);
_local3++;
};
dragMode = "none";
numFound = 0;
}
public function isValidRange(_arg1, _arg2:Point):Boolean{
if (_arg1.x == _arg2.x){
return (true);
};
if (_arg1.y == _arg2.y){
return (true);
};
if (Math.abs((_arg2.x - _arg1.x)) == Math.abs((_arg2.y - _arg1.y))){
return (true);
};
return (false);
}
public function drawOutline(_arg1:Sprite, _arg2, _arg3:Point, _arg4:Number){
var _local5:Point;
_local5 = new Point((offset.x + (spacing / 2)), (offset.y + (spacing / 2)));
_arg1.graphics.lineStyle(outlineSize, _arg4);
_arg1.graphics.moveTo(((_arg2.x * spacing) + _local5.x), ((_arg2.y * spacing) + _local5.y));
_arg1.graphics.lineTo(((_arg3.x * spacing) + _local5.x), ((_arg3.y * spacing) + _local5.y));
}
public function endGame(){
gotoAndStop("gameover");
}
function frame1(){
stop();
addEventListener(Event.ENTER_FRAME, loadProgress);
}
function frame5(){
playAgainButton.addEventListener(MouseEvent.CLICK, clickPlayAgain);
}
function frame3(){
stop();
startButton.addEventListener(MouseEvent.CLICK, clickStart);
}
public function mouseRelease(_arg1:MouseEvent){
var _local2:*;
if (dragMode == "drag"){
dragMode = "none";
outlineSprite.graphics.clear();
if (isValidRange(startPoint, endPoint)){
_local2 = getSelectedWord();
checkWord(_local2);
};
};
}
public function foundWord(_arg1:String){
var _local2:int;
drawOutline(oldOutlineSprite, startPoint, endPoint, 0xFF00FF);
playSound(theSound1);
_local2 = 0;
while (_local2 < wordsSprite.numChildren) {
if (TextField(wordsSprite.getChildAt(_local2)).text.toUpperCase() == _arg1){
TextField(wordsSprite.getChildAt(_local2)).textColor = 0xFF00FF;
};
_local2++;
};
numFound++;
if (numFound == usedWords.length){
endGame();
};
}
function frame4(){
startWordSearch();
}
public function clickStart(_arg1:MouseEvent){
gotoAndStop("play");
}
public function getSelectedWord():String{
var _local1:*;
var _local2:*;
var _local3:Number;
var _local4:String;
var _local5:int;
var _local6:*;
var _local7:*;
_local1 = (endPoint.x - startPoint.x);
_local2 = (endPoint.y - startPoint.y);
_local3 = (Math.max(Math.abs(_local1), Math.abs(_local2)) + 1);
_local4 = "";
_local5 = 0;
while (_local5 < _local3) {
_local6 = startPoint.x;
if (_local1 < 0){
_local6 = (_local6 - _local5);
};
if (_local1 > 0){
_local6 = (_local6 + _local5);
};
_local7 = startPoint.y;
if (_local2 < 0){
_local7 = (_local7 - _local5);
};
if (_local2 > 0){
_local7 = (_local7 + _local5);
};
_local4 = (_local4 + grid[_local6][_local7].getChildAt(0).text);
_local5++;
};
return (_local4);
}
public function playSound(_arg1:Object){
var _local2:SoundChannel;
_local2 = _arg1.play();
}
public function clickLetter(_arg1:MouseEvent){
var _local2:String;
_local2 = _arg1.currentTarget.getChildAt(0).text;
startPoint = findGridPoint(_arg1.currentTarget);
dragMode = "drag";
}
public function cleanUp(){
removeChild(gameSprite);
gameSprite = null;
grid = null;
}
function frame2(){
stop();
beginButton.addEventListener(MouseEvent.CLICK, clickBegin);
}
}
}//package