Flash on the Beach 09 – Play with Vectors

This year I was only able to go to Flash on the Beach on the very last day. Never the less it was once again a really awesome experience and I learned a lot and got a lot of inspiration as well. I’ll try and post my notes from all the talks I’ve seen, but it might take a while…

23-09-2009 9.00 Koen de Wieggheleire – Play with Vectors
Koen did a very in depth talk about the Vector class in AS3.

The Vector class is a dence array which means that it can’t have any gaps, so something like the below would throw an error:

ActionScript

  1. myVector[0] = 'bla'; // See how we're skipping positions 1 and 2?
  2. myVector[3] = 'something else';

You can you an array as a ‘data provider’ to populate a Vector:

ActionScript

  1. myVector = Vector.<String>(myArray);

Using the Vector class will give you a performance boost of about 40 to 60%.
Unfortunately you can’t directly bind to a Vector in Flex, you can however write a wrapper class and bind to that. 😉

How to use in 3D

The Matrix3D class is somewhat complex to understand, but the image below should clarify it a bit

You can use myDisplayObject.transform.matrix3D to retrieve a DO’s Matrix3D or assign a new matrix3D to it. There are also build in methods to user rather than creating a new Matrix3D all the time, see http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html

Nice thing I only found out now about matrixes: You can skew objects with it! Rock on!!! \m/

How to use with 2D

Pretty much the entire graphics API in Flash relies on Vectors. The drawPath() method below (which is pretty much the core of drawing vector shapes) takes two Vectors (the Vector data type) as arguments.

ActionScript

  1. graphics.drawPath(commands, data)
  • the commands argument is a Vector containing GraphicPathCommands
  • the data argument is a Vector containing x and y pairs that determine the path to draw.

The new Illustrator can export to FXG and you can actually import this FXG data on the fly in Flash, parse it and draw the exact same.

Some notes on UVT (texture) mapping:

  • U matches up with the x location
  • V matches up with the y location
  • T determines the focal length

The right value for T can be calculated with the following formula: T = focalLength / (focalLength + z)

Useful links: