Sections

  • Search Chrome Cow

Design a Day



I’ve collected together all of my various experiments with Flash on this page. Most of what you will find here are snippets of code and small movies that test certain features of Flash, or solve some small, specific problems. There are also a few game-like projects.

Each of the movies posted here also show the source code (or at least the important bits). The goal is to create a resource for other people who are learning Flash, especially ActionScript . All of the exercises below are created in Flash 8. Some of them will work in earlier versions, some will not.

<

 Drawing Regular NGons

Documentation: Palabre 0.6

I am in need of a Flash compatible Socket Server, and found a great open source project, Palabre, with poor docs. This is info gather from docs, forums, etc. [ Link ]


 Drawing Regular NGons

Drawing Regular NGons

I have a project in progress that require me to draw regular NGons (Pentagons, Hexagons, Octagons, etc). I’ve posted the Flash movie and the source code for drawing them, using a simple rotation equation. [ Link ]


Learning Flash

Learning Flash

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.

  • Loading Text as Unicode
  • Create and Format a Dynamic Text Field
  • Write-On Text in a Fixed Amount of Time
  • Using Checkboxes
  • The Game Loop

  [ Link ]


Radial Solo Ball

Radial Solo Ball

Flash game number one. Basic goal, build a game with a main execution loop.

First experimentation with collision detection in Flash. [ Link ]


eRadiRace

eRadiRace

A simple wall avoidance game.

First iteration using built-in collision handling in Flash.
[ Failed ]

Second iteration using Flash 8’s Draw API. [ Somewhat Final ]


 



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 = new LoadVars( );
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
Flash 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("display_txt", getNextHighestDepth(), 20, 10, 460, 200);
//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
Flash 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.

var displayMe = "This was created for the Design-A-tron, to write-on a text string of arbitray 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
Flash TextWriteOn.fla


Here is a re-write of the base eRadiRace code, using the new Flash 8 Draw API to make the trails and do the simple collision.

 


 

Added a musical score. Now at v0.254

It still has a few bugs:

  • Not all sounds seem to be playing when called (intermittent).
  • [Fixed] A last minute change to add the Tutorial screen has made the avatars disappear after the first round.
  • Collision could be tightened up just a bit.
  • The frame where the player collides with the line is delayed in drawing by about a half a second, which makes it look like they shouldn’t have lost.

I’ll fix that avatar thing and post up the game loop code.