This is a method frequently used among flash developers, when they want to multiply an object. Is not hard to understand I’m sure that this will be a piece of cake for you guys.
First, create a new class in your project and name it Object, this will be the class that will draw the object that we will multiply. Let’s take a look in our file(Object.as):
package hc { import flash.display.Sprite; public class Object extends Sprite { public function Object():void { with(this.graphics) { beginFill(0x333333,1); drawRect(10,10,10,10); endFill(); } } } }
As you can see in the Object class I only draw an object. Now let’s see how our main class looks like:
package { import flash.display.Sprite; import hc.Object; public class main extends Sprite { private static const DISTANCE_X:Number = 15; private static const DISTANCE_Y:Number = 15; private var container:Sprite = new Sprite(); private var numberX:Number = 10; private var numberY:Number = 10; public function main() { for(var i:int = 0; i < numberX; i++) { for(var j:int = 0; j < numberY; j++) { var obj:hc.Object = new hc.Object(); obj.x = DISTANCE_X * i; obj.y = DISTANCE_Y * j; container.addChild(obj); addChild(container); } } } } }
Make sure that your Object class is inside a folder(package).
[kml_flashembed movie=”http://www.horiacondrea.com/wp-content/uploads/article/Use%20a%20matrix%20to%20multiply%20an%20object/Other.swf” height=”480″ width=”620″ fversion=”9″ useexpressinstall=”true” /]
A magazine theme would make ur blog look nicer 🙂
How do you extend on the Z aix ?
If you want to do something is 3D, you will probably want to use one of the following : papervision3d, alternativa3d etc.. Because when you work in 3D space, you will have to face lots of problems. Like: view, X rotation, Y rotation and more.
But, if you want to do some experiments, you can easily add another loop, and you will have something like this: