views:

1036

answers:

2

i am trying to produce clouds effect in my flash animation using as3

i am able to generate clouds through action script but the real problem is how to make them be generated at one end of the screen and travel diagonally to the other end...

any thoughts?

+3  A: 

This is the barebones version of what you want to do, the handleEnterFrame function will run once each frame (and for each cloud, but I'm guessing you'll prefer the simpler solution)

package {

    import flash.display.Sprite;
    import flash.events.Event;

    public class Cloud extends Sprite{

     public var xSpeed:Number = 1;
     public var ySpeed:Number = 1;

     public function Cloud() {
      addEventListener(Event.ENTER_FRAME, handleEnterFrame);
     }

     public function handleEnterFrame(e:Event):void {
      x += xSpeed;
      y += ySpeed;
     }

    }

}

Set "Export for actionscript" in the Linkage menu of your cloud symbol, and set the class name to "Cloud".
This code should be placed in an external file called "Cloud.as", in the same directory as your flash file.
(thanks to aaaidan for pointing this out)

grapefrukt
Remember that you'll need to set "Export for actionscript" in the Linkage menu of your cloud symbol, and set the class name to "Cloud". This code should be placed in an external file called "Cloud.as", in the same directory as your flash file.
aaaidan
A: 

Check out a package called Tweener: http://code.google.com/p/tweener/

I use Tweener for all my animation needs. You simply write a line of code like so:

Tweener.addTween(cloudObject, {x: targetX, time: 3.0});