Archive for January, 2007

Okay I’ve been slacking off

Thursday, January 11th, 2007

Blame CSI.

Anyway, its been an exciting past few days for me. University choices and such. So exciting, in fact, that I have been neglecting this blog (again). Many apologies!

So, in a month, a Bachelor of Software Engineering course awaits me. Australia’s the location. So hook me up if you’re gonna be in the area in Semester 1, 2007!

Undocumented Method - addFrameScript();

Friday, January 5th, 2007

A little looking around the web, and this stood out.

From http://www.flashguru.co.uk/undocumented-actionscript-3/#comments

It allows you to specify a function that is called when the playhead of the Movieclip timeline enters the specified frame number. Their are four parameters to the method, i only completley understand the purpose of the first two, the other two are worth investigating more.

While I am trying to get away from scripting on frames, there are definately situations where it is essential (and this simply provides a cleaner way to do frame-scripting, but not on a frame). One of my older projects (currently stalled) involved a MovieClip that had animations for turning in different directions, and I had to use copious amounts of frame-scripting for me to know when each “animation” had completed. This should come in handy.

Anyway, Senocular came up with the appropriate usage of this method:

addFrameScript(...rest);

Arguments must be in pairs, frame-number followed by function. Note that frame-number 0 refers to the very first frame. Also, your MovieClip must have that number of frames before it will execute.

addFrameScript(2, frameMethod1, 5, frameMethod2);
function frameMethod1():void
{
  trace("Frame 3 reached");
}
function frameMethod2():void
{
  trace("Frame  6 reached");
}

Grid Class

Friday, January 5th, 2007

Ever got sick of creating 2 dimensional arrays? Wanted a class to do it for you?

Try this class I whacked together in a flurry of inspiration (I’m kidding myself - give me a break).

dynamic class Grid extends Array{
  private var vw:uint
  private var vh:uint

  public function Grid(vx:uint, vy:uint)
  {
    vw = vx;
    vh = vy;    

    for (var i:int=0; i< vx; i++)
    {
      this[i] = new Array(vy);
    }
  }

  public function get width():uint
  {
    return vw;
  }
  public function get height():uint
  {
    return vh;
  }
}

What this class does at the moment is relatively simple.

You simply declare a variable as a new Grid like so

var myGrid:Grid = new Grid(10,10);

That will create a 2 dimensional array 10×10. You can then reference it as you’d do a normal 2 dimensional array:

trace(myGrid[4][1]);

And that’s the end of my trivial actionscript pursuits. Enjoy!

<<<<<<< .mine