I have created a Flash program which has no purpose at all. Yeah, I know it sounds dumb for wasting my time to create this, but I am still glad that I manage to develop a simple program in Flash through the concept of Object-Oriented Programming.
Still I feel that the way I wrote the codes are not efficient and lots of repetitive. So yeah I still need to buck up on my OOP.
You could check out the Flash program though by clicking the little red button in the Flash above. LiL.Jon will be there to help you out on how to use the program.
import caurina.transitions.*;
const Z = 90;
const X = 88;
var statusMove:int = 1;
var count:int; //Determines the case for the dynamic text
var temp:int;
var isJonIn:Boolean = false;
var introTimer:Timer = new Timer(7000); //Timer for 4 seconds each dialog in intro
var randomTimer:Timer = new Timer(12000);
var timer:Timer = new Timer(8000);
var usedBeforeArray:Array;
/****************************************
[0] = Clicked on auto run before
[1] = Used custom size field before
[2] = Used custom rotate before
[3] = Clicked on rotation button before
[4] = Clicked on arrow buttons before
*/
usedBeforeArray = new Array(false, false, false, false, false);
var randomSayArray:Array;
randomSayArray = new Array(”JonLoh created me when he was 18 years old. He have no idea why he created me.”,
“Oh yeah, do come back and visit www.JonLoh.net next time.”,
“JonLoh took about 3 days developing this no-so-useful Flash program.”,
“I have a headphone stucked on my head because JonLoh loves music and he wants me to hear it 24/7.”,
“Simple fact about the Bible - 66 books, over 40 inspired authors, about 85 prophecies being fulfilled.”,
“Need someone to design and build your website? JonLoh would be able to do that. Contact him!”,
“JonLoh feels the way he programmed this Flash isn’t efficient and lots of repeating codes. That’s bad!”,
“Interesting read-up for Software Engineers: Google for No Silver Bullet.”);
btn1.addEventListener(MouseEvent.CLICK, theBtn1);
btn2.addEventListener(MouseEvent.CLICK, theBtn2);
btn3.addEventListener(MouseEvent.CLICK, theBtn3);
btn4.addEventListener(MouseEvent.CLICK, theBtn4);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
bg_mc.btnSquare.addEventListener(MouseEvent.CLICK, theSquare);
function theBtn1(e:Event):void{ Tweener.addTween(bg_mc, {width: stage.stageWidth * 0.2,
height:stage.stageHeight * 0.2, time: 1}); };
function theBtn2(e:Event):void{ Tweener.addTween(bg_mc, {width: stage.stageWidth * 0.5,
height:stage.stageHeight * 0.5, time: 1}); };
function theBtn3(e:Event):void{ Tweener.addTween(bg_mc, {width: stage.stageWidth * 0.8,
height:stage.stageHeight * 0.8, time: 1}); };
function theBtn4(e:Event):void{ Tweener.addTween(bg_mc, {width: customWidth.text,
height:customHeight.text, time: 1}); };
btnTop.addEventListener(MouseEvent.CLICK, theBtnTop);
btnRight.addEventListener(MouseEvent.CLICK, theBtnRight);
btnBottom.addEventListener(MouseEvent.CLICK, theBtnBottom);
btnLeft.addEventListener(MouseEvent.CLICK, theBtnLeft);
btnCenter.addEventListener(MouseEvent.CLICK, theBtnCenter);
function theBtnTop(e:Event):void{ bg_mc.y -= 2; jonForMove(); };
function theBtnRight(e:Event):void{ bg_mc.x += 2; jonForMove(); };
function theBtnBottom(e:Event):void{ bg_mc.y += 2; jonForMove(); };
function theBtnLeft(e:Event):void{ bg_mc.x -= 2; jonForMove(); };
function theBtnCenter(e:Event):void{ Tweener.addTween(bg_mc, {x: stage.stageWidth * 0.5 - 30,
y:stage.stageHeight * 0.5, time: 0.5, rotation: 0});};
rotateClock.addEventListener(MouseEvent.CLICK, theRotateClock);
rotateAntiClock.addEventListener(MouseEvent.CLICK, theRotateAntiClock);
btnRotate.addEventListener(MouseEvent.CLICK, theCustomRotate);
function theRotateClock(e:Event):void{
bg_mc.rotation += 2;
jonForRotate()
};
function theRotateAntiClock(e:Event):void{
bg_mc.rotation -= 2;
jonForRotate()
};
function theCustomRotate(e:Event):void {
Tweener.addTween(bg_mc, {time: 0.5, rotation: customRotate.text});
};
function keyDownListener(e:KeyboardEvent):void {
if (e.keyCode==Keyboard.LEFT) {
theBtnLeft(e);
}else if (e.keyCode==Keyboard.RIGHT) {
theBtnRight(e);
}else if (e.keyCode==Keyboard.UP) {
theBtnTop(e);
}else if (e.keyCode==Keyboard.DOWN) {
theBtnBottom(e);
}else if (e.keyCode==Z) {
theRotateAntiClock(e);
}else if (e.keyCode==X) {
theRotateClock(e);
}else if (e.keyCode == Keyboard.ENTER) {
if (stage.focus == customHeight || stage.focus == customWidth) {
theBtn4(e);
} else {
theCustomRotate(e);
}
}
};
function theSquare(e:MouseEvent):void {
if(usedBeforeArray[0] == false) {
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
liljon.jonSays.text = “You have just clicked the box to auto turn and move it. Click on it again to stop it!”;
usedBeforeArray[0] = true;
} else {
callJonOut();
callJonOutIntro();
}
if (statusMove == 1) {
statusMove = 0;
keepMoving();
} else {
Tweener.addTween(bg_mc, {x: bg_mc.x, y: bg_mc.y, rotation: bg_mc.rotation, time: 1});
statusMove = 1;
}
};
function keepMoving() {
Tweener.addTween(bg_mc, {x: Math.random()*(stage.stageWidth-50), y: Math.random()*stage.stageHeight,
rotation: Math.random()*180, time: 0.8, onComplete: keepMoving});
};
function countDown() {
timer.stop();
timer.addEventListener(TimerEvent.TIMER, callJonTimeOut);
timer.start();
};
function callJonIn() {
Tweener.addTween(liljon, {y: liljon.y-60, time: 0.6});
countDown();
randomTimer.stop();
isJonIn = true;
};
function callJonOut() {
Tweener.addTween(liljon, {y: 400, time: 1});
randomTimer.start();
isJonIn = false;
};
function callJonTimeOut(e:TimerEvent):void {
callJonOut();
};
function callJonOutIn() {
countDown();
Tweener.addTween(liljon, {y: 400, time: 0.3, onComplete: callJonIn});
isJonIn = false;
};
customHeight.addEventListener(MouseEvent.CLICK, theCustomHeightField);
customWidth.addEventListener(MouseEvent.CLICK, theCustomWidthField);
customRotate.addEventListener(MouseEvent.CLICK, theCustomRotateField);
function theCustomHeightField(e:MouseEvent):void {
if (usedBeforeArray[1] == false) {
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
liljon.jonSays.text = “The box will transform based on the values you defined. Press Resize or Enter key to resize.”;
usedBeforeArray[1] = true;
}
};
function theCustomWidthField(e:MouseEvent):void {
theCustomHeightField(e);
};
function theCustomRotateField(e:MouseEvent):void {
if (usedBeforeArray[2] == false) {
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
liljon.jonSays.text = “The box will rotate according to the entered value. The recommended value would be 0 to 180.”;
usedBeforeArray[2] = true;
}
};
function jonForMove() {
if (usedBeforeArray[4] == false) {
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
liljon.jonSays.text = “You could use the keyboard to move it too with the UP, DOWN, LEFT and RIGHT arrow key.”;
usedBeforeArray[4] = true;
}
};
function jonForRotate() {
if (usedBeforeArray[3] == false) {
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
liljon.jonSays.text = “You could use the keyboard to rotate it too. Z for clockwise, X for anti-clockwise.”;
usedBeforeArray[3] = true;
}
};
function jonIntro() {
introTimer.addEventListener(TimerEvent.TIMER, callJonTimeOutInIntro);
introTimer.start();
callJonInIntro();
};
function callJonInIntro() {
jonSaysWhat();
Tweener.addTween(liljon2, {y: liljon2.y-60, time: 0.6});
isJonIn = true;
};
function callJonOutIntro() {
Tweener.addTween(liljon2, {y: 410, time: 1});
introTimer.stop();
randomTimer.addEventListener(TimerEvent.TIMER, jonSaysRandom);
randomTimer.start();
isJonIn = false;
};
function callJonTimeOutInIntro(e:TimerEvent):void {
callJonOutInIntro();
};
function callJonTimeOutIntro(e:TimerEvent):void {
callJonOutIntro();
};
function callJonOutInIntro() {
Tweener.addTween(liljon2, {y: 410, time: 1, onComplete: callJonInIntro});
jonSaysWhat();
count++;
isJonIn = false;
};
function jonSaysWhat() {
switch (count) {
case 0:
liljon2.jonSays.text = “Hello there! I am JonLoh’s web representative, lilJon and it’s very nice to meet you!”;
break;
case 1:
liljon2.jonSays.text = “You might have seen me before in his previous Flash work where you have to wake me up and sleep.”;
break;
case 2:
liljon2.jonSays.text = “Anyway, you are currently looking at JonLoh’s first interactive Flash program.”;
break;
case 3:
liljon2.jonSays.text = “This little Flash program is a simple program where you can define the size of the box…”;
break;
case 4:
liljon2.jonSays.text = “Move the box around the empty area and also to rotate the box clockwise or anti-clockwise!”;
break;
case 5:
liljon2.jonSays.text = “To start off, click on any box button under the Size section in the right panel. Try it!”;
introTimer.stop();
introTimer.addEventListener(TimerEvent.TIMER, callJonTimeOutIntro);
introTimer.start();
break;
default:
break;
}
};
function jonSaysRandom(e:TimerEvent) {
var decision:int = 0;
var randomSay:int = 0;
decision = Math.random() * 2;
do {
randomSay = Math.random() * randomSayArray.length;
} while(temp == randomSay);
trace(”randomSay: ” + randomSay);
trace(”temp: ” + temp);
if (decision != 0) {
liljon.jonSays.text = randomSayArray[randomSay];
if (isJonIn == true) {
callJonOutIn();
callJonOutIntro();
} else {
callJonIn();
}
temp = randomSay;
}
};
jonIntro();