Diagonal movement in flash animation using as3

I am trying to create a cloud effect in my flash animation using as3

I can generate clouds via an action script, but the real problem is how to get them to be generated at one end of the screen and move diagonally to the other end ...

any thoughts?

0


source to share


2 answers


This is the barebones version of what you want to do, the handleEnterFrame function will run after every frame (and for every cloud, but I assume you 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 on 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 aaaidan for pointing this out)

+3


source


Have a look at a package called Tweener: http://code.google.com/p/tweener/

I am using Tweener for all my animation needs. You just write a line of code like this:



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

0


source







All Articles