PDA

View Full Version : Scroll MC with simple actionscript+Best book to learn Actionscript


Lynx75
01-03-2003, 02:31 PM
hello everyone!

Ive build a flash movie where is a button called "move" and an MC (where it rapresent a small alien) called "alien".
I wish to scroll this "alien" from x=0 to x=100 when I press the button.
I wish to make a small game and I need to know how to do this.

Another question is:
which goog,but very good book could be the best buy to learnn FlashMx actionscript in deep?


many thanks
bye

mad_A
01-03-2003, 03:10 PM
on row 1 of the movie put the action -
_root.runYN=true;
function slowdown(){
if(_root.ball._x<100){
_root.temp=int((100 -_root.ball._x)/2)+1;// move halfway over
_root.ball._x+=_root.temp;
}else{
_root.runYN=false;
}
}


then on the button put -

on(release){
_root.scroll.play();
}


then on the root put a clip with two frames, and give it the instance name "scroll". On frame 1 put the actions (how many frames you put in this movie decides how fast the scroll is) -

if (_root.runYN==true){
_root.slowdown();
}else{
stop();
}


on frame 2 put thew following action -
gotoAndPlay (1);



this is a slow down scroll, fading out. Th change it to a simple scroll change the function slowdown to -

function slowdown(){
if(_root.ball._x<100){
_root.ball._x+=1;
}else{
_root.runYN=false;
}
}



I hope that is clear enough...

Lynx75
01-03-2003, 03:34 PM
ok,I did just a test movie where I dont have the button,but I need the concept of the scroll,so here we go because there are a few gap:

_root.runYN=true;
--this is boolean,for what exaclty?

_root.temp=int((100 -_root.ball._x)/2)+1;// move halfway over
--this is a quarter because 100-_root.ball._x is equal to 50 (if I position the ball at x= 50) then I divide by 2 and I get 25 but the +1 for what I need?

ive created a simple fla where Ive got this MC "alien and in the first frame of the timeline Ive wrote:

_root.alien.onEnterFrame = function(move) {
_root.alien._x+=5;
};

how can I stop it for example at x=230?

any suggestion for the book?

many many tnx!

p.s: I was in Cork for 7months in 1999! 8)...cool place ireland!

mad_A
01-03-2003, 03:50 PM
Yes, runYN is a boolean. It is for the checker that will stop the ball scrolling if the user presses the scroll button and the ball is already at 100.

The +1 is for the idea of a faded out scroll - you are constantly devidign the distance between the ball and it's end point by 2, and adding this to it's x. Without the 1 it would go into an infinate loop at 99.9999999999999999999. By adding 1 we ensure that it will end at a figure above 100 (but below 101), so alowing the boolean runYN to be set to false stopping the loop. There are a lot of ways of writing that, probably simpler ones too. I was justr writing off the top of my head.

To change the value where it will stap just swap the new value for the 100 values in the code.

Cheers for the compliments on Ireland. I'll try to make it to Italy some time so I can return the favor!