E: me@sabisin.com | T: +4915168651209

Tile based / Object based Scrolling engine

This is just the very basic idea, but it’s general enough to work as a platform for a wide range of games. Depending on the requirements you can add all sorts of things. Why is this method fast? The reason is that we don’t have any nested for loops. There are actually only 2 for.. in loops which are always performed each frame. When we enter a new area then we have 4 additional for.. in loops, but that happens far from every frame (unless the scrolling speed is very high). A simple data structure and pre-calculations also help, and by using local variables as much as possible. And I’m sure there is still room for improvement…

This method is not necessarily faster than a gotoAndStop engine, but it has many advantages in my opinion:

The tiles can have any size, in a gotoAndStop all tiles must be of the same size
It’s very easy to animate objects, like moving platforms
Relatively easy to add parallax effect on an object per object basis. In a gotoAndStop you would have to make a couple of “layers” and then scroll them with different speed.
You can place tiles in the same object on top of each other
Objects can be on top of each other. You can easily have 5 objects overlapping, and it will not be slower than if they were placed edge to edge.
It’s easy to make interactive objects, like swings (see the Flash MX Platform Demo at the end of the level)

What drawbacks are there?

If you want 100% of the screen covered in tiles at all times, this method could get a bit slower than a gotoAndStop unless you group the tiles very carefully.
It’s a bit more difficult to create a level editor. With a gotoAndStop engine, it’s very easy to create an editor to build maps. However, there is a nice way to actually build the levels in Flash using the tile set and then loop through the scene to create the map data.

ActionScript 3 : Get a Class Reference by Class Name

If you need to get a reference to a class in ActionScript 3, but only know the class name, then you can use the flash.utils.getDefinitionByName to create an instance of the class. For example:

package {
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;

	public class DynamicCall extends Sprite
	{
		public function DynamicCall()
		{
                    var ClassReference:Class = getDefinitionByName("ClassName") as Class;
		}
	}
}

Example :

var ClassReference:Class = getDefinitionByName("String") as Class;
var str:String = (new ClassReference("SAbi Sin") as String);
trace(str);

This basically creates an instance of the String class, from the class name “String”. getDefinitionByName takes the entire class path, so if you wanted to create an instance of MovieClip, you would provide the entire path:

var ClassReference:Class = getDefinitionByName("flash.display.MovieClip") as Class;

Simple useful Snippet.

bUllshit