VectorClip AS3 Class

Custom class dependencies: Vector2D

Working with vectors – Part 1, Part 2, Part 3

So far everything done in the series “Working with vectors” have been utilities to help with the calculation of trigonometric values. Now we will apply it to something that will be displayed, a MovieClip! Or in this case, what I call a VectorClip.

The VectorClip class simply extends MovieClip, and adds the methods of which we already added to the Vector class that extended Point. A new property of direction is now complimentary to the existing property of rotation. Both properties are useful in working with this class.

The overall goal is achieved now that we can move a MovieClip (or any other DisplayObject these methods are applied to) by simply calling the ‘move’ methods which are: move, left, right, forward, and backward. All of these methods are based on a magnitude and angle, which in this case, the angle is the property of direction. The reason the direction property stays separate from the original rotation property is simple. It is because sometimes, we may want to rotate the object without changing it’s direction and vice versa.
There is another Boolean property called rotationBased. This property, when set to true, simply combines the properties of direction and rotation. So that when one is set, the other is also.

After explaining all of this, here are a couple of simple examples. In the second, please click anywhere on the stage. You will see the MovieClip turn and move toward that location. This is all done with the vector movement defined in the VectorClip class.

VectorClip Example:

[swfobj src=”https://jidd.jimisaacs.com/files/2008/08/example-VectorClip.swf” width=”350″ height=”250″ align=”center” required_player_version=”10.0.0″]

VectorClip Example 2:

[swfobj src=”https://jidd.jimisaacs.com/files/2008/08/example-VectorClip2.swf” width=”350″ height=”250″ align=”center” required_player_version=”10.0.0″]

Finally here is the class used in the above examples and is the end result of the series. Remember to check to other posts for the required classes for each step of the process. Thank you and enjoy!

Comment if you have any questions, or suggestions.


Posted

in

, ,

by

Comments

6 responses to “VectorClip AS3 Class”

  1. Og2t Avatar
    Og2t

    This is great, been playing with self oriented particles, that will help me a lot, thanks!

  2. Joe Avatar

    Hi,
    I am somewhat new to programming. I have been working in Processing for a little while and have recently taken up actionscript. These vector classes are great and will fit perfectly into a project I am working on but, being new to actionscript, I am not entirely sure how to use them. Could you please post the flas for the above examples so I can see how you did it? It would be a tremendous help, not only to my current project but even more so to my understanding of how to work with actionscript in general.
    Thanks.

  3. Lorenzo Avatar
    Lorenzo

    very good, thank’s

  4. Inês Amorim Avatar
    Inês Amorim

    Hi. I am student at Portsmouth University, UK, and I am starting with AS 3, but I am not specially gift on it. This code is amazing and it would be pretty useful in the course work I am doing in this right moment, because we can use other people's classes to particular behaviors. my problem is, as I don't know much about As3 I have been struggling about how to match this code to the one I already have. First of all I am not sure how to import the classes to other classes, because i am getting errors all the time. Second, you link the Vector Clip class to a movie clip. I can't really do that, because the movie clip I want to affect with is already linked to another class. So I would to know if you can advise about what to do, please? It would be really important for my work, my learning and my ability to understand AS3 better.

    Thank you very much.

  5. […] Jim IsaacsJune27th2008 Custom class dependencies: NoneWorking with vectors – Part 1, Part 2, Part 3What is a ‘vector’? Well, it is just 2 numbers used for one thing. It is a direction and […]

  6. […] Working with vectors – Part 1, Part 2, Part 3 […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.