Wednesday, December 28, 2011

Abstract Class in AS3 - How To

Here is a hack for making an class that will function as an abstract class:
Cut and paste code below:
3 Files in code below:
[1]: The Base Abstract Class
[2]: The Sub Class that Extends the Abstract Class
[3]: .FLA file testing it.

ABSTRACT CLASS CODE:_________________________________________________

package com.JMIM02.ABS_TestAbstract{
    //Class Summary:
    //A test to see if I can make a TEST abstract class by simply throwing an ERROR in the constructor
    //Of the class that is an abstract class. Would only work if you DON'T need to call the superMethod
    //When using a class that extends this class.
    public class ABS_TestAbstract{

        protected var testVar:Number = 77;

        public function ABS_TestAbstract() {
        protected function overrideToEmpty():void{
            throw new Error("Abstract Class Cannot be instantiated by itself");


SUPERCLASS/SUBCLASS/DERIVED CLASS CODE:_______________________________

package com.JMIM02.Uses_TestAbstract{
    //Class Summary:
    //A test class that tests if I can make a "Pseudo Abstract Class"
    //By making the Base-Class's constructor throw an error.
    //This would prevent the class from being directly instantiated.
    import com.JMIM02.ABS_TestAbstract.ABS_TestAbstract;
    public class Uses_TestAbstract extends ABS_TestAbstract {

        public function Uses_TestAbstract() {
            testVar = 333;
            trace("testVar===" + testVar);
        //make an empty function so that you can instantiate the base-class.
        protected override function overrideToEmpty():void{}//[x]

.FLA FILE TESTING CLASS:______________________________________________

import com.JMIM02.Uses_TestAbstract.Uses_TestAbstract;
import com.JMIM02.ABS_TestAbstract.ABS_TestAbstract;

var inst:Uses_TestAbstract = new Uses_TestAbstract();

//block of code below WILL throw error since you cannot directly instance the base-class:
var base:ABS_TestAbstract = new ABS_TestAbstract();

Monday, December 26, 2011

Chain Reaction Proof Of Concept for Asteroids Game

After I make my simple asteroids game with a twist... It would be cool to make
a game with a style like this but using the same chain-reaction concept:

On an unrelated note: I like this game's loading screen:

I like this game design for it's simplicity and ease to create:

Saturday, December 24, 2011

Collision Physics For My Asteroids Game Working!

I went on a rather large side-quest of coding some max-script for money.
And then I got distracted by deciding to work on UI elements instead of game
physics since game physics was wearing me down. I took another crack at my
physics over the past few days and now I have what I what I believe to be a fairly
acceptable collision manager that resolves collisions in an elastic manner.

Friday, December 23, 2011

Menu Button Class AS3, with arrow control

I feel like I've been working on this TOO long. But I thought an approach of
working on UI stuff FIRST, and then the game-content might help me organization-wise. I think the next step here is to make a "mock-game"
like "CowClicker". Something really simple where all the basics are in place.

menuButton Class Code

Internally: I call this class:
Does NOT yet have arrow controls in it.
Also, will glitch out if you slide the cursor over the button REALLY FAST
when the app is first initialized. Fixed in latest version.

Friday, September 30, 2011

How to override .x and .y properties of MovieClip in as3

//Note: super() method is used to invoke
//the original method you are overridding.
public override function get x():Number{
    return super.x;
public override function set x(xCoord:Number):void{
    super.x     = xCoord;

public override function get y():Number{
    return super.y;
public override function set y(yCoord:Number):void{
    super.y     = yCoord;

Wednesday, September 28, 2011

Deval Wrapper

I found the D.eval library very hard to work with for what I needed it to
do, after 2 days of messing around with it, I created a simple wrapper class
for it that does my bidding:

More about D.eval here:

Source code for my class below for your use: (highlight, cut and paste)

package com.JMIM02.DynamicGetSet{
    import r1.deval.D; //This library can be downloaded at:
    //What this class does:
    //Allows you to dynamically get and set values of attributes in a class.
    //Use in my "attribute spy" class to get and set values of selected class

    //This class is a key piece in the parameter editor UI I am writing for flash.
    //When you click any object, you will see all of it's public variable and
    //accessor values and be able to set them.
    //Though many programmers frown upon using "eval()", the eval() command
    //makes my attribute editor work with ANY class. Without eval(), I would
    //have to modify any class with special get/set methods specifically
    //designed for use by my parameter editor.
    public class DynamicGetSet {
        public var iObj:Object; //Must be public, else will NOT work.
        public var rtnV:*     ; //return value for D.eval command.
        public function DynamicGetSet() {
            // constructor code
        }//Empty Constructor.
        public function setVal(
        inObj,       //Object you are acessing.
        propertyStr, //Property as string.
        valueString  //Value as string.
            iObj = inObj;
            var eStr:String = "iObj." + propertyStr + "=" + valueString;
        public function getVal(
        inObj,       //Object you are acessing.
        propertyStr  //Property as string.
            iObj = inObj;
            D.eval("rtnV = iObj.publicVar",this);
            return rtnV;

Tuesday, September 27, 2011

Interactive Vector

Interactive Vector Class I created to help me visualize the output of my "vector combining" class. The ball physics had problems with balls getting stuck together, and I needed to back them away from each other when this happened. I needed to do this in a non-jarring way, so that it would not be noticeable to the user.

Initially here is what I did:
Balls A and B are intersecting and need to back off from one another. They are both currently moving parallel to each other on the Y-axis. Added normalized vector AB to ball B, and normalized vector BA to ball A so that they would move away from each other AND the effect would not be jarring as to totally change the current direction (parallel on the Y-axis) of the balls.

Problem: This method added ENERGY to the system. And after a few frames,
all of the balls in the system would end up moving at ridiculously fast speeds.

Fix: Add The new vectors, but scale down the resulting vector if it's magnitude is GREATER than the original. In this system, I wasn't really worried about losing velocity, but I am sure it could happen. And... If I find I need something that keeps the magnitude exactly that of the original, not simply capping the magnitude, then I will write that code. Till then, this is good enough.

Improved Collision Physics

Some improved collision physics I wrote.
Think it is finally good enough to make a multi-ball
breakout-style game. Now I need to write a class for it.

Saturday, September 24, 2011

Dispenser Box AutoGenerated PlaceHolder Art

This updated "DispenserBox" UI element takes a bitmap snapshot of the first
frame of the class it dispenses. This makes it convenient because I no
longer have to create "place holder" art in each dispenser box.
The thumbnail graphics are now auto-generated.

Friday, September 23, 2011

Dispenser Box UI class test

I wanted a UI element that would have a thumbnail of an item that could be clicked and dragged onto the stage. The biggest challenge was generating sprite placeholder
images from the actual classes. When you click on one of the balls in the small square boxes, you are actually interacting with a placeholder sprite.
When the ball is dropped, an instance of the class associated with that placeholder
sprite is spawned. The placeholder sprite then returns to the origin of the
dispenser box. Sprite placeholder images were used rather than the ACTUAL
class objects because I did not want the objects to react with the mouse
until dropped into position. This would also create problems since both the UI and
the spawned class instance inside of it might end up fighting for focus in strange ways.

Wednesday, September 21, 2011

FragBox Prototype

An exercise in:
1. Extending my "click draggable" base class to make another class.
2. Embedding a movieclip inside of a class.
(The graphics are actually part of the class, not the .fla file
that created the .swf)

Thursday, August 18, 2011

Boom Grid Game: Fleshing Out!!! Yay!

Note: Lowest score wins... Combos could be used to redeem bombs.
That make it possible to set off chain reactions without clicking. Each click on a ball will add a point to your clicks total.

It's going to be like golf.

Monday, May 2, 2011

WireParam As3

Thought on constrainable object structure:

You can have bound functions, but you cannot have bound properties.
That said, constraints should operate through bound functions
such as getX and setX.

This will enable "WireParameters" in flash like wireparameters in max.

Stacking Order / Draw Order Explained. AS3

Original Thread Link:

Post By:neznein9
Whenever you use addChild, the object is put on the top of the display list (highest z-index). You can use a couple different methods to manually set the index - also, remember that you have to use an index thats in bounds, you can only set an index to 100 if there are 100 other things on stage.

addChildAt(mc, 0); <= this will add to the back

addChildAt(mc, 10); <= this will add to layer 10 and bump anything already there

setChildIndex(mc, 20); <= this moves mc to index 20, bumping anything else

setChildIndex(mc, this.numChildren - 1); <= bring mc to the top

swapChildren(mc, mc2); <= switches the two

swapChildrenAt(0, 10); <= switches whatever is at 0 with whatever is at 10

Sunday, May 1, 2011

Pass By Reference in AS3

Turns out, you can't do it.


var A1:Array = [1,2,3,4];
function theFunction(someArray:Array){
var otherArray:Array = [555,555,555];
someArray = otherArray;
trace("A1==" + A1);


Now, you are probably saying:
[1]: Why do this?
[2]: Why not use return value?

I wanted to make a function called: removeReferences.
Usage: removeReferences(theArray,theObject);
It would look for references of theObject in theArray and
set those references to null. Then the next pass would create a new
array where the null references would not be included.

My function still works.... But it has to be called as such:
theArray = removeReferences(theArray,theObject);

Which to me is ugly ugly syntax.
It is akin to saying: theArray = theArray.push(theObject);

Unfortunately, all the other workarounds are even uglier...

Resource Management time

Todo: Learn how to completely remove movieclips from stage.
If I am going to make a particle that spawns other particles, that
could create huge memory leaks if I don't figure out resource management.

Saturday, April 30, 2011

Let their be pausebutton!

So... What is the next step here? I am thinking I really need to finish
my collideable and constrainable line class. My linked-line class was nice
visually, but the class was not structured with standards in place that
would make it work well with a dependency graph.

Senocular Tint Snippet
05-11-2007, 11:25 AM
here is an example using the Tween class with a tint. Assumes a movie clip with the instance name "clip"
import fl.transitions.*;
import fl.transitions.easing.*;

// function to transition from one colorTransform to another
function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;

// start and end colors for tween
var startColor:ColorTransform = new ColorTransform(); // default color, no tint
var endColor:ColorTransform = new ColorTransform();
endColor.color = 0xFF0000; // end color of red

// create tween; use "" for property since no
// property is being tweened; just using the
// Tween class here to handle the animation
// using the values 0 and 1 (0% to 100%)
// over a time period of 50 frames
var tween:Tween = new Tween(clip, "", Strong.easeOut, 0, 1, 50);
// listen for the TweenEvent.MOTION_CHANGE event to
// perform the custom color tween
tween.addEventListener(TweenEvent.MOTION_CHANGE, tweenTransform);

// TweenEvent.MOTION_CHANGE handler using interpolateColor
// to set the colorTransform of clip (tween.obj) based on
// the startColor and endColor properties defined earlier
function tweenTransform(event:TweenEvent):void {
// use tween position for interpolation of
// start and end colors (value 0 - 1)
clip.transform.colorTransform = interpolateColor(startColor, endColor, tween.position);

Note To Self: Don't forget drop shadows sometime.

Using Tween Class for pre-packaged interactivity

Next step: Procedurally generate drop shadows that are linked to movieclips.
These drop shadows will NOT be bound to the raster surface and thus will
not contribute to drawing on the surface. Only contribute to visibility to
help user understand object is interactive.

MouseOver vs Rollover

Friday, April 29, 2011

Save Image and download from server?

Char to KeyCode As3

Char to keycode looks pretty impossible... But I think I found a script that does it...

Why Char to keycode?

Well, for readability.

Example: keyBoardListener.BindKeyToFunction("K",true,theFunction);
K = the K key.
true = case sensitive. AKA, bind to capital K, not the k key.
theFunction = the function that will execute when you press the k key.

This Andy guy looks to have done a badass job at what I need:

Test of new raster function and constrainable class

PREVIEW IMAGE: (Interactive App Further Down!)

INTERACTIVE APP. Click, Drag And Throw!

Thursday, April 28, 2011

Click and and throw balls

The text will go away if you click it. Bad design on my part...
By the way, you can totally click and throw the balls! Do it!

Sunday, April 24, 2011

Bouncing Ball with capsule collision with mouse

Download Source: ****HERE****

Capsule collision with mouse made so that it is easier to grab balls moving at
high speed. Also, if you hold down the mouse, it will grab a ball when the mouse
is over something. No need to time the clicking.

This feature will probably be able to be toggled on and off depending on
what the class is being used for.

The arrows are from a simple "VectorDisplay" class I wrote to debug
the user friendlyness of the ball throwing. It shows you the velocity vector
upon throwing the ball.

Saturday, April 23, 2011

MoveAble Line Research

Looks like, once you draw a line in flash, you cannot access the vertices
of that line and move them. Even though the line itself may still be a vector.
You have to store the line data somewhere else, and clear the screen
and redraw everything if you want to move the line.

Resource that has what I need:

Friday, April 22, 2011

Bouncing Ball with more user friendly throwing. BETA01

Download Source: ****HERE****

I implemented a queque that averages the velocity of the ball while you are
holding onto it to make the throwing more user friendly. I think
I may have forgotten to clear the que after you let go... Because
sometimes it has erratic behavior.

May want to weight the velocities. If you go back 5 frames slowly, and then go forward VERY FAST, you should go forward.

Throwable Click Draggable Class

Download Source: ****HERE****
So, it is a bit glitchy with the throwing, because you only have a sample of
1 frame to determine the new velocity. Next step is to get an average of say... the previous 5 frames to create a new velocity.

Thursday, April 21, 2011

Reflection Vector Research

Reflection Vector Research:

Vect1 is the direction of the ball before hitting the wall
Vect2 is after the wall
WallN is the normal of the wall
DOT is the dot product
Vect2 = Vect1 - 2 * WallN * (WallN DOT Vect1)
note that this will work for 3D vectors too

v' = 2 * (v . n) * n - v;
Where '*' is the scalar multiplication operator, '.' is the dot product of two vectors, and '-' is the subtraction operator for two vectors. v is reflected off of the surface, and gives a reflection vector v' which is used as the new velocity of the object.

Dot Product By Hand:

Basically: [1]Multiply the X components together.
[2]Multiply the Y components together.
[3]Add the X and Y of the new point2 value
together to get a single scalar float value.

F02: Click Draggable Class That Moves

Download Source: ****HERE****
This is the same click draggable class as before. But now it moves when you are
Not clicking on it. The next version after this will be one you can grab and toss.

F01:ClickDraggable Class Demo

Download Source: ****HERE****
My current maxscript project is taking a while to develop.
And I want to have something tangible to show for my efforts every day.
Thus, here is a clickDraggable class I made in flash today: