var startTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, myStopwatch);
function myStopwatch(event:Event) {
var timePassed:int = getTimer()-startTime;
var seconds:int = Math.floor(timePassed/1000);
var minutes:int = Math.floor(seconds/60);
seconds -= minutes*60;
var timeString:String = minutes+”:”+String(seconds+100).substr(1,2);
stopwatch_txt.text = timeString;
}
Source:
Stopwatch
stop();
addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event)
{
var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
var mcKLoaded:int=mcBytesLoaded/1024;
var mcKTotal:int=mcBytesTotal/1024;
my_txt.text=”Loading: “+mcKLoaded+”K of “+mcKTotal+”K”;
if (mcBytesLoaded>=mcBytesTotal)
{
removeEventListener(Event.ENTER_FRAME, loading);
gotoAndStop(2);
}
}
Source:
Preloader2
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event)
{
if (bone_mc.hitTestPoint(mouseX,mouseY,true))
{
pointText.text=”hitTestPoint: Overlaps”;
} else
{
pointText.text=”hitTestPoint: No Overlaps”;
}
dog_mc.x=mouseX;
dog_mc.y=mouseY;
if (dog_mc.hitTestObject(bone_mc))
{
objectText.text=”hitTestObject: Overlaps”;
} else
{
objectText.text=”hitTestObject: No Overlaps”;
}
}
Source:
DetectinCollisions2
Mouse.hide();
addEventListener(Event.ENTER_FRAME, myCursor);
my_cursor.mouseEnabled = false;
function myCursor(event:Event) {
my_cursor.x = mouseX;
my_cursor.y = mouseY;
}
Source:
Custom_Cursor
Learning ActionScript 3.0: A Beginner’s Guide
Editorial Reviews
Product Description In this book, authors Rich Shupe and Zevan Rosser share the knowledge they’ve gained from their years as multimedia developers/designers and teachers. Learning ActionScript 3.0 gives you a solid foundation in the language of Flash and demonstrates how you can use it [...]
Essential ActionScript 3.0
Editorial Reviews
Review
Adobe Developer Library is a co-publishing partnership between O’Reilly Media and Adobe Systems, Inc. and is designed to produce the number one information resources for developers who use Adobe technologies. Created in 2006, the Adobe Developer Library is the official source for comprehensive learning solutions to help developers create expressive [...]
Object-Oriented ActionScript 3.0
Object-Oriented ActionScript 3.0
Editorial Reviews
Product Description
Learn object-oriented programming in ActionScript 3.0
Covers both the Flash and Flex environments
Includes design patterns, custom frameworks, data binding, and other crucial techniques
Object-oriented programming (OOP) is something that is usually considered a black art for hardcore programmers, not a topic of conversation for Flash developers. However, when adobe introduced ActionScript [...]
var letters:Array=new Array(”a”,”b”,”c”,”d”,”e”);
var myRandomNumber:Number=Math.floor(Math.random()*5);
my_txt.text=letters[myRandomNumber];
my_keyboardText.text=”Key Pressed:”;
stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);
function keyUsed(event:KeyboardEvent)
{
var str:String=my_txt.text;
my_keyboardText.text=”Key Pressed: “+String.fromCharCode(event.charCode);
if (event.charCode==str.charCodeAt(0))
{
my_txt.text=”Correct”;
} else
{
my_txt.text=”Wrong”;
}
}
Source:
abc
import fl.lang.Locale;
Locale.autoReplace=true;
var IDS_TEXT:Object=test_text;
var IDS_TEXT2:Object=test_text2;
var IDS_TEXT3:Object=test_text3;
Locale.setLoadCallback(updateText);
function updateText(success:Boolean):void
{
var arr=Locale.stringIDArray;
for (var i = 0; i < arr.length; i++)
{
this[arr[i]].text=Locale.loadString(arr[i]);
}
}
// load default language
Locale.loadLanguageXML(”en”);
// buttons
en_bt.addEventListener(”click”,en_select);
ru_bt.addEventListener(”click”,ru_select);
function en_select(event:Event)
{
Locale.loadLanguageXML(”en”);
}
function ru_select(event:Event)
{
Locale.loadLanguageXML(”ru”);
}
Source:
localization
//*********************************************************************
//************************** Text input *****************************
//*********************************************************************
var myTitleText:TextField = new TextField();
myTitleText.width=400;
myTitleText.text=”enter something and click enter;)”;
addChild(myTitleText);
var inputMyFormat:TextFormat = new TextFormat();
inputMyFormat.font = “Tahoma”;
inputMyFormat.size = 14;
inputMyFormat.color = 0xff0000;
inputMyFormat.bold=true;
var myInputText:TextField = new TextField();
myInputText.type = TextFieldType.INPUT;
myInputText.defaultTextFormat = inputMyFormat;
myInputText.x = 10;
myInputText.y = 30;
myInputText.height = 18;
myInputText.width = 200;
myInputText.border = true;
stage.focus = myInputText;
addChild(myInputText);
myInputText.addEventListener(KeyboardEvent.KEY_UP, checkForReturn);
function checkForReturn(event:KeyboardEvent) {
if (event.charCode == 13) {
acceptInput();
}
}
function acceptInput() {
var theInputText:String = [...]