Hi all. I’m using the code below to move an instance down a page but I’d like it to run on a loop (just downwards not up and down). What do I need to add to the code?
Thanks in advance.
onClipEvent(enterFrame) {
speed = 8;
this._y += speed;
}
Hi all. I’m using the code below to move an instance down a page but I’d like it to run on a loop (just downwards not up and down). What do I need to add to the code?
Thanks in advance.
onClipEvent(enterFrame) {
speed = 8;
this._y += speed;
}
look at tween class which is repeated when it gets to the bottom of a page
Thanks but unfortunately (for whatever reason) the place where I’m working wants pure AS and don’t use classes.
This is identical to the earlier question you asked about changing the alpha value:
Rather than provide the code, I’ll leave it as an exercise for you to figure out…suffice to say that you need to include a similar condition that checks when the movieclip has moved past the bottom of your stage, and which then moves it back to its original starting position.
Wahey! I had a feeling it would be something similar. Thanks Glos. I got it to stop at a certain point with this:
onClipEvent (enterFrame) {
speed = 45;
if (this._y < 130) {
this._y += speed;
}
}
But I can’t for the life of me set up the loop. I tried this but it didn’t work.
onClipEvent (enterFrame) {
speed = 8;
if (this._y < 520) {
this._y += speed;
}
if (this._y = 520) {
this._y = 0;
}
}
Heya mate, your problem right now seems to be the missuse of onClipEvent.
onClipEvent(enterFrame){
//do something
}
will trigger the actions inside as many times per second as your frame rate is. So say your frame rate is 30, //do something will be repeated 30 times per second, as long as the movie clip is on stage.
onClipEvent(load){
//do something else
}
will only trigger the events inside the clipevent once, when the movie clip loads (or when it first appears on stage).
onClipEvent(load){
speed = 10; //loading the variable only once
}
onClipEvent(enterFrame){
_y += speed; //repeats the action each frame
}
Hope I helped.
Hmmmm. I’m not sure I follow. The movement code below works using ‘enterFrame’ but doesn’t as a ‘load’ when attached to the object. I had it in my head that it would run along the lines of getting the object to move to a certain place, stopping and then the code would run again.
onClipEvent (enterFrame) {
speed = 45;
if (this._y < 130) {
this._y += speed;
}
}
Some tips.
Firstly, move away from placing code directly on symbols and place it on the timeline instead.
Secondly, try to write down the effect you want to achieve. This is commonly referred to as pseudo-code which is then easily converted to AS code:
MC starts at x = ?? and y = ??
At the frame rate of the movie, move MC downwards
If the MC moves off the stage, return it to the original start position
This code should do what you want:
// Initialise start positions
start_x = 200; // horizontal position of movieclip
start_y = 0 - my_mc._height; // places movieclip above stage
// Assign start positions to the movieclip
my_mc._x = start_x;
my_mc._y = start_y;
// Use onEnterFrame handler to repeat at movie frame rate
my_mc.onEnterFrame = function() {
speed = 10; // Speed of descent
this._y += speed; // Apply motion
if (this._y > Stage.height) { // Check if movieclip is offstage
this._y = start_y; // If so, reset start position
}
};
Adjust start_x, speed, and my_mc name as appropriate
Thanks Glos. I’ll check that code out. You’re right with regards to changing the way I approach code, I’ve always been a designer and the realisation that (with FLASH at least) I have to learn how to write script has left me floundering a little. Thanks for the advice. While I have your indulgence, could I ask if you could recommend any sites (other than this one of course) that could help me learn AS?
Best place to start are the help files that come with Flash, particularly the Tutorials and Samples that are provided.
Next best place would be to start here http://www.kirupa.com/forum/showthread.php?t=190941 with the four sites listed and the Useful Flash ActionScript Tutorials and Resources link.
There are also a ton of books on the subject, with many focusing specifically on actionscript rather than how to draw stuff in Flash…check out the reference section of your library.
:: Copyright KIRUPA 2024 //--