Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Animate using actionscript 1

Status
Not open for further replies.
Dec 24, 2001
857
GB
Is it easy to use actionscript to tell a box to move from on place to another?

Also, is it smooth?

If any one has tutorials on how to do this it would be appreciated.

Just as a note, heres what I'm doing:

I have numerous movie clips which have animation in them. They each have tellTarget and Stop commands in so that on my main stage, there is actually only one frame; the movies tell each other when to continue etc.
However, at some point, the movie clips have to move from one location to another. I wanted to do this using actionscript but have no idea on how to.

Thanks
 
It's possible... And Wangbar has posted several examples of this. Look in his posts. Regards,

oldman3.gif
 
Objects are placed on the stage via actionscript using _x and _y coordinates.

The origin (0,0) is in the top left corner of the stage.

If your box clip is called "box" (instance name) then placing it at point 100, 100 on the stage would be accomplished with this script:

box._x=100;
box._y=100;

If you want to move it horizontally then you could put something like this in a two frame loop or clipEvent:

box+=2;

Actionscript can be as smooth as you like - moving one pixel at a time with a high frame rate looks very slick.

 
Hmmm...easy enough...now heres the hard part.

Imagine this little scenario:


MC with an instance name of 'box' is at co-ordinates (0,0).

It has to move to co-ordinates (100,100).

When it reaches that point, it stops and tells MC 'box2' to alpha in (_root.box2._alpha = 100).



The whole movie is running at 20fps

Is this easy to do?

Thanks
 
Attach this to the box that you want to move and it should give you what you're after:

onClipEvent (load) {
this._x = 0;
this._y = 0;
_parent.box2._alpha = 0;
}
onClipEvent (enterFrame) {
if (this._x<100) {
this._x++;
this._y++;
} else if (_parent.box2._alpha<100) {
_parent.box2._alpha += 10;
}
}
 
One last thing...how do I change the speed at which its running? I tried replacing the '++' with '+5' etc, but if I do it just stops. I need to keep the movie at 20fps because of everything else which is in it.

Do you have any tutorials on this sort of thing?

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top