Posts Tagged ‘AS3’

Labs: Line-Of-Sight

Friday, November 23rd, 2007

Did a quick little experiment with Line-Of-Sight Calculations in AS3.0. I’m not too happy with it at the moment, and trying to find a balance between performance and accuracy, but you can see what I have done so far in the Labs.

Experiment Focus:

  • flash.geom.Point;
  • Line of Sight

View Experiment

My FlashDeveloping Tools

Wednesday, November 21st, 2007

Came across a post by Wayne Marsh today, documenting the tools he uses to develop in Actionscript 3.0 without his wallet being set back by a dollar. And it is exactly the same as how I do it as well, with the long awaited release of FlashDevelop 3 looming.

So be sure to go over for a look at how you can start developing in Actionscript 3.0 for less than a penny.

Abstracting Assets from Actionscript in AS3.0 - Asset Libraries

Friday, November 16th, 2007

Introduction

I write this article because it seems to me that quite a few people still have no idea how to duplicate external assets (such as duplicating MovieClips, for example). Thus, I decided to take this opportunity despite there being quite a few articles that document this. If I haven’t bored your by now, read on!

First, Some History

Assets in Flash are normally quite coupled with the SWF. This is probably a result of the long years of timeline scripting that has been burnt into our memories. In Actionscript 2.0, however, the process of abstracting Assets from Actionscript was slightly alleviated through the copious use of duplicateMovieClip(). I too, used to be an avid user of duplicateMovieClip(), until I made the transition to Actionscript 3.0, But before then, duplicateMovieClip() was my quick and dirty solution to many situations I came across in Flash.

Abstracting Assets from Actionscript in Actionscipt 2.0 was relatively simple. One need only separate his/her assets into separate swf files, and simply loadClip() them into the SWF, and employ the use of duplicateMovieClip(). In Actionscript 3.0, however, this situation has changed as Adobe saw fit to remove (or shall we say, omit) the duplicateMovieClip() method.

Now, Adobe recommends the use of the “new” keyword to instantiate multiple instances of a Class. From the Actionscript 2.0 Migration reference:

In ActionScript 3.0, use the new operator to create a new instance.

This doesn’t really help us abstract our Assets from Actionscript. Most of us who have played around enough in Actionscript 3.0 would know that this requires that the Class be part of the SWF calling it, and in facts forces us to embed our assets within the SWF. Using the Loader class to import external SWFs does not expose any classes that we may use to invoke the “new” operation. At least, not obviously, as we shall see later.

(more…)

Papervision3D Clipping Issues

Tuesday, July 17th, 2007

Gah! What is with all the clipping issues I get? The problem arises specifically at angles close to multiples of 90. I suppose these are problems arising mathematically due to some special trigonometric properties, and seriously hope they get fixed soon.

Again, of course, the library is still currently in Beta status. So it is probably not perfect. However these are the kind of things I’m hoping they will iron out as time goes along.

Unfortunately, I can’t seem to grasp 3D Rendering techniques, and I won’t be making my own engine anytime soon! There goes my Rubik’s Cube idea…

Papervision3D is impressive, but…

Friday, July 13th, 2007

I’ve been playing abit with Papervision3D recently, and I’m seriously impressed with their work. However, there were some parts I had trouble with, but I’m willing to let it pass, as it is still in Beta status. Seemingly trivial things like “changing the textures of each side of a cube” seems to require some subclass. And in some cases, I still found evidence of bad clipping. Though that is probably my fault.

Over the next few days, look out for my wonderous journey in learning Papervision3D.

Removing Children of Containers

Saturday, July 7th, 2007

As everybody knows, not keeping track of referenced objects is BAD. And the one thing worse than not keeping track of referenced objects is dead references.

For example, if you had an instance of an object, you must dereference everything associated with it before it is garbage collected. This may seem like child’s play to most veterans; things like event listeners are easily removed. However, it is important to note that in the case of DisplayObjects, your DisplayObject may have children that are also referencing it (through the ‘parent’ property). Removing the DisplayObject at this stage will therefore result in dead references to its children and itself! You’ll end up with massive amounts of memory leak as time goes along.

Luckily, there is a handy Event you can use. The Event.REMOVED Event fires when an object is removed from the display list! So with a bit of code, one can easily remove all children when it is removed from the display list.

this.addEventListener(Event.REMOVED, iveBeenRemoved, false, 0 , false);
private function iveBeenRemoved(e:void):void
{
   while (this.numChildren != 0)
   {
      this.removeChildAt(0);
   }
   this.removeEventListener(Event.REMOVED, iveBeenRemoved, false);
}

Simply one of the things we might overlook in our coding practices. I myself will try to remember about child objects.

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!

AS3 Date()

Saturday, December 30th, 2006

Darron Schall blogs about the AS3 Date() constructor, and very interesting parameters you can pass to the constructor to acheive different results!

Check it out Here!

dLabs

Saturday, December 23rd, 2006

My good friend Joachim lent me some space on his server, and that is where I am currently hosting dLabs (dazzLabs), my AS3 Demo Showcase! Many Kudos to you mate!

I’ve added the link to my blogroll, and you can get a direct link here. I’ll be adding any future experiments I do to that site, but of course, this is where the interesting blogging is.

On a separate note, dLabs.blog hit a high of 39 hits yesterday! I was very thrilled! And in preparation for the official launch, I am currently preparing a Mini-Series entitled “AS3: What’s It to You?” so be sure to keep an eye out for that! In the meantime, lets hope I’ll hit 50 hits before the new year!

Lastly, Steven Schelter (who did the awesome Physics computeSpectrum() demo below) of Schelter Studios offered to exchange links. I’m most honoured to get noticed by him, so be sure to pay him a visit too.

Awesome physics with computeSpectrum()

Saturday, December 23rd, 2006

Possibly the most creative demo for the computeSpectrum() I’ve seen so far. You’d think that the computeSpectrum() function doesn’t have much practical uses besides creating visualisations for sound, but its inspiring to see people think out of the box sometimes.

Check it Out Here

<<<<<<< .mine