interesting thing i've descovered..
you are adding listener to the timer
Now i think that's a logical choice but for a while i was thinking that i had to tell object to listen to the timer...
well so here is my preloader test code with timer class.
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
var velocity:Number = 1;
var loadProgress_txt:TextField = new TextField();
var siteLoader:Loader = new Loader();
var myFog1:URLRequest = new URLRequest("Source/images/Fog2.png");
var myTrigger:Timer = new Timer(2000, 20);
// initialize
siteLoader.load(myFog1);
siteLoader.alpha = 0.5;
siteLoader.x = 0;
siteLoader.y = 0;
loadProgress_txt.x = 200;
loadProgress_txt.y = 200;
loadProgress_txt.autoSize = TextFieldAutoSize.LEFT;
// add listeners
siteLoader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
siteLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
siteLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, showLoadResult);
function showPreloader(evt:Event):void {
addChild(loadProgress_txt);
}
function showProgress(evt:ProgressEvent):void {
loadProgress_txt.text = "loaded:"+evt.bytesLoaded+" from "+evt.bytesTotal;
}
function showLoadResult(evt:Event):void {
removeChild(loadProgress_txt);
addChild(siteLoader);
myTrigger.start();
myTrigger.addEventListener(TimerEvent.TIMER, loadAnother);
}
function loadAnother(evt:TimerEvent) {
siteLoader.x -= velocity * 10;
}
not really a pretty one yet but i can build on this to make a pretty one. using timer was easy too.
Tuesday, June 26, 2007
ActionScript 3 Timer class
Posted by SONARHYTHM Logic Pro School at 9:45 PM
Labels: actionscript, actionscript 3.0, flash, programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment