To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-22-2004, 09:08 PM   #1
MoldRat
Junior Member
 
Join Date: Oct 2004
Posts: 1
Do while loops

Hey, I am trying to have a movie clip shoot where the mouse position is when they click a button, heres my script, I havent done any action script in a long time so I can't really see whats wrong.

code:
on (release) {
shootx = _xmouse;
shooty = _ymouse;
CowboyMC.play();
duplicateMovieClip(bullet,bullet01,1);
bullet01._x = CowboyMC._x;
bullet01._y = CowboyMC._y;
do {
bullet01._x = bullet01._x - 5;
bullet01._y = bullet01._y + shooty * 0.2;
} while(bullet01._x < shootx && bullet01._y < shooty)
}

MoldRat is offline   Reply With Quote
Old 10-22-2004, 09:16 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
The problem is that you can't produce animation by doing a series of discrete movements inside a loop. This is because the statements in the script execute between frame-drawing. All those movements will happen very quickly and then when the next frame is drawn, the bullet will already be at the target.


If you want script to execute for the next few frames, you need a way to say "execute this script in the future". You can use an onEnterFrame handler for this, or setInterval.

Here's an example:

code:

on (release) {
shootx = _xmouse;
shooty = _ymouse;
CowboyMC.play();
duplicateMovieClip(bullet,bullet01,1);
bullet01._x = CowboyMC._x;
bullet01._y = CowboyMC._y;

bullet01.onEnterFrame = function()
{
this._x = bullet01._x - 5;
this._y = bullet01._y + shooty * 0.2;
if (this._x >= shootx || this._y >= shooty)
{
// we're there, delete this eventhandler so we stop moving
delete this.onEnterFrame;
}
};
}

__________________
jbum is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:00 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.