[AS]
package
{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.text.TextFieldType;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
public class TimerTimeline extends Sprite
{
private var theTimeline:Timer;
private var theShowTyping:TextField;
private var theShowTypeFormat:TextFormat;
public function TimerTimeline()
{
theShowTypeFormat = new TextFormat();
theShowTypeFormat.font = "Arial";
theShowTypeFormat.color = 0x000000;
theShowTypeFormat.size = 16;
theShowTypeFormat.align = TextFormatAlign.CENTER;
theShowTyping = new TextField();
theShowTyping.type = TextFieldType.DYNAMIC;
theShowTyping.defaultTextFormat = theShowTypeFormat;
theShowTyping.autoSize = TextFieldAutoSize.LEFT;
theShowTyping.text = "H";
this.addChild(theShowTyping);
theTimeline = new Timer(500, 11);
theTimeline.addEventListener(TimerEvent.TIMER, doTheAnimation);
theTimeline.start();
var resetButton:Sprite = new Sprite();
resetButton.graphics.lineStyle(1, 0x000000);
resetButton.graphics.beginFill(0x000000, .2);
resetButton.graphics.drawRect(0, 0, 65, 20);
var resetButtonTXT:TextField = new TextField();
resetButtonTXT.type = TextFieldType.DYNAMIC;
resetButtonTXT.selectable = false;
resetButtonTXT.defaultTextFormat = theShowTypeFormat;
resetButtonTXT.autoSize = TextFieldAutoSize.LEFT;
resetButtonTXT.text = "replay";
resetButton.y = 25;
resetButtonTXT.y = resetButton.height/2 + resetButtonTXT.height/2;
resetButtonTXT.x = resetButton.width/2 - resetButtonTXT.width/2;
resetButton.buttonMode = true;
resetButton.addEventListener(MouseEvent.CLICK, replayTimerHandler);
addChild(resetButtonTXT);
addChild(resetButton);
}
private function doTheAnimation(event:TimerEvent):void
{
var currentFrameOn:int = event.target.currentCount;
switch (currentFrameOn)
{
case 1:
theShowTyping.appendText("e");
break;
case 2:
theShowTyping.appendText("l");
break;
case 3:
theShowTyping.appendText("l");
break;
case 4:
theShowTyping.appendText("o");
break;
case 5:
theShowTyping.appendText(" ");
break;
case 6:
theShowTyping.appendText("W");
break;
case 7:
theShowTyping.appendText("o");
break;
case 8:
theShowTyping.appendText("r");
break;
case 9:
theShowTyping.appendText("l");
break;
case 10:
theShowTyping.appendText("d");
break;
case 11:
theShowTyping.appendText("!");
break;
}
}
private function replayTimerHandler(event:MouseEvent):void
{
theTimeline.stop();theShowTyping.text = "H";
theTimeline.reset();
theTimeline.start();
}
}
}
[/AS]
Can someone please, please, tell me what is wrong with the above code.
I use it as a teaching tool so I need to know every possible thing that could
be wrong with it. Please, I need someone who will seriously look at it and
tell me what’s wrong, whether it be a coding best practice issue, a garbage collection
issue, programming or whatever. The code works, but according to one person,
it’s laughable, and I really need to know why. As of now my 8+ years of ActionScript
programming have been laughed at, and I need to know why.
There is really only one person who I trust to give a good answer, he has 6 eyes.
But everyone else please let me know what you think of the above code, good or bad.
Thanks