|
-
Animation through for loops
Hey everyone , been a while since Ive posted here 
Ok this has always been on my mind and so finally deciding not to be lazy decided to give it a try. And thats animating objects using for loops.
Let me give you a run down of what exactly Im trying to accomplish. I have this blue ball movieclip in my library in which I use to attach to the main movie. Now when the movie loads, I have the following code:
code:
onLoad = function () {
_root.attachMovie("blue", "blue1", 0);
_root.blue1._x = 300;
_root.blue1._y = 100;
//
for (var i:Number = 0; i<10; i++) {
_root.blue1._x += 5;
}
};
Now the problem isnt the fact its not working , but the fact that it works the wrong way
Instead of animating the ball moving +5 on its x axis , its just plops it down the line as soon as the movieloads. So it gets there, but you dont see it happening.
Im just wondering how I would go about having it animate and if I would need to put some sort of delay. I know I could use a tween, but as this is for a game, the speed needs to be controlled
Anyways, thanks everyone
-
Senior Member
Code:
onLoad = function () {
_root.attachMovie("blue", "blue1", 0);
_root.blue1._x = 300;
_root.blue1._y = 100;
//
_root.blue1.framecount=0;
_root.blue1.onEnterFrame = function(){
this.framecount+=1;
if (this.framecount <10) {
this._x+=5;
} else {
delete (this.onEnterFrame);
}
}
};
You for loop is executed in one single frame that's why you can't see the MC moving.
Last edited by fil_razorback; 01-04-2006 at 05:58 PM.
-
Hey Razor,
Thanks so much for the response, I had no clue what I was doing. Anyways it works , so many thanks 
Learning something new everyday
-
Senior Member
You're welcome
-
hey i was lookin for that code to thanks im just postin so i can find it back
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|