Interactive Forest

From my previous post, animation.Float, I had the basic example of the animation class that I wrote to simulate dandelion seeds floating in the wind.  Well I had some free time this weekend and decided to keep my AS3 skills sharped and went on to add interactivity!    Depending on the location of your mouse will vary on the speed of the wind blowing the seeds around.  Farther away you go from the middle the faster the wind gets.  The interactivity is also directional and when you click on one of the seeds they disappear.

The Float class was one of the very first classes that I wrote on my own. Pretty much after I got done reading a book about OOP in AS2, I started this class.  Looking back now, it was pretty rough.  To add in the interactivity and to port the class over to AS3, I pretty much gutted the whole thing and started new, but it is neat to see that I have come a long way in such a short time.

Now the seeds are in a new Dandelion class that extends Float. Float contains a wind object which is shared among the other instances of dandelion seeds (kind of like a singleton, not really fond of them personally, but that is a different post).  After that is was simple to add in the required mouse detection class and update the wind velocity based on the mouse position.


There are still a few bugs left, if you are in FireFox switch to another tab and then come back.  Also I want to enforce the wind velocities a little better in case the mouse position is too extreme.  To enhance it I want to make it 3D by splitting the picture into layers and having the seeds go between the tree.  The 3d would also have the smaller seeds be removed from the stage earlier to make it look like it landed in the background of the image.

[UPDATE]: Github Repository for the Interactive Forest

Licensed under Creative Commons, so feel free to use them in your project and if you do please let me know.

4 thoughts on “Interactive Forest

  1. @lirio Boquin

    Hi, WOW thank you for share your work and help us to learn more from Flash/Flex and AS.

    I’m trying to download the source, but the link it’s broken.
    I trying to run your code on Flex 3, will work?

    Thank you Craig.

  2. Amelia

    Hi Craig,

    Firstly, thanks for sharing this code, I’m doing something similar but I’m still new to as3, would like to study your source file but the download source link is broken..

    I did try to download your classes and link them up, trying to understand package took me some time and I’ve this error, (I renamed Float as Flyfly)

    ArgumentError: Error #1063: Argument count mismatch on Flyfly(). Expected 1, got 0.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()

    Which I’ve no idea on how to fix it.
    I would really appreciate it if you could shed some light on how to fix that error 😀


  3. Craig Post author

    Hey everyone,
    I moved the source code to github. I’ve updated the post with a link.

    @Amelia – looks like you fotgot to pass in a wind instance to Flyfly.
    var wind – new Wind(5,5);
    var flyfly = new Flyfly(wind);

    One suggestion I would make is to have your Flyfly class extend the Float class instead of renaming it.

    public class Flyfly extends Float


Leave a Reply

Your email address will not be published. Required fields are marked *