Thursday, December 18, 2008
Sub - Random movement of objects in Macromedia Flash.
What we are going to make is this:
Requirments - Flash MX or Higher versions, with ActionScript 1/2/3.
Level - Basic ActionScript
This is very simple but effective tutorial for Flash actionscript beginners. With this you can move any object in your movie randomly. And as you make this movie with actionscript the file size is as low as as 1 KB.
Step 1 :- Set the screen size and background to Flash default(you may change this as you need though).
Step 2 :- Then draw an object and covert it to a symbol.
Step 3 :- Now double click on the symbol to edit it, At the first frame of that movie clip paste this code.
acceleration = 10
newpos = function () {
ranx = Math.round((Math.random ()*250));
rany = Math.round ((Math.random ()*250));
}
newpos();
this.onEnterFrame = function() {
this._x += ((ranx-this._x)/acceleration);
this._y += ((rany-this._y)/acceleration);
if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
newpos();
}
};
Step 4 :- Go back to stage and Test movie press Ctrl+Enter.
Step 5 :- Copy the same object and paste it 3-4 times on stage. And change the colors using Object Properties.
That will make the movie look much better and attractive.
If any question please post in comments.
Related Posts :
0 Responses to "Random moving object in Flash"







Post a Comment