Since returning from GDC, I have been fired up to learn Flash as a tool for doing some simple gameplay prototyping. It has been rewarding, and at times fairly frustrating, as Flash has some interesting quirks of implementation. It has…personality.
So this is to be a dumping ground for bits and bobs of code and information that I’ve learned, and might help others over some rough spots. No particular order or theme. Just nuggets of Flashy goodness.
Loading Text as Unicode
Use the standard loadVars method:
myLoadVars.load("unicodeSample.utx");
myLoadVars.onLoad = function (success) {
if (success) {
textWindow_txt.text = myLoadVars.quote1;
} else {
trace("Load Failed");
}
}
The trick is to save the text out as UTF-8 or UTF-16, with the *.utx file extension. I use JEdit for this, though there are a number of other free unicode text editors available.
Download the Flash File
unicode.fla
Create and Format a Dynamic Text Field
This code creates a dynamic text field, creates a text formatting object, and applies the text format to the newly created text object.
//createTextField(textObjectName, Zdepth, X, Y, width, height)
my_txt.autoSize = true;
display_txt.text = "Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.";
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "Times"
my_fmt.size = 33;
my_fmt.bold = false;
my_fmt.color = 0×0055CC;
my_fmt.kerning = true;
display_txt.selectable = false;
display_txt.antiAliasType = "normal";
this.onEnterFrame = function() { // Update Format Every Frame (for button update)
display_txt.setTextFormat(my_fmt);
}
Download the Flash File
dynamicText.fla
Write-On Text in a Fixed Amount of Time
This code writes a text string into a dynamic text field, left-to-right, one or more characters at a time, in a fixed amount of time.
This was created for the Design-A-tron, to write-on a text string of arbitrary length, in the amount of time it took to play the gears running animation and sound. It is completely dependent on the framerate of your movie.
displaySize = displayMe.length;
delay = 70; // The larger, the slower the write on
displayLoop = 0;
endFlag = 0;
displayRate = displaySize/delay;
onEnterFrame = function() { // Runs this loop every frame
if (endFlag == 0) { // Only Done for Duration of Write-On
// Text Write-On
tmp = displayMe.substr(0, displayLoop);
display_txt.text = tmp;
displayLoop = displayLoop + displayRate;
if (displayLoop > displaySize) {
// This writes on the last few characters
// if the math doesn’t come out right
// And sets the end condition for the loop
endFlag = 1;
display_txt.text = displayMe;
}
}
}
Download the Flash File
TextWriteOn.fla





















December 16th, 2006 at 10:05 am |
nice 1