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)