Javascript and dhtml into flash

hi |

i’m trying to translate some very cool experiments done in javascript and dhtml into flash.

a guy i work with put these together and although i’ve got a good basic knowledge of programming, his stuff is just beyond me and i’m looking for someone to help me understand his code and translate it to flash. i really want to learn from this.

the experiments can be found at:

http://www.cowboyscripts.org/javascript/mousetrails.html

he said that besides some code that’s specific to dhtml the code he has can be translated almost verbatim into flash.

i’m attaching my initial .fla with the code i brought over. i thought it might be a good place for me to start. it’s not much but i’m taking small steps.

you can view his javascript/dhtml code on the url listed above.

i’m really looking forward to working thru this and understanding it and hopefully learning a lot. that’s my end goal.

any help will be greatly appreciated. plus, i thought it might be fun for some people to check out what this guy is doing. he is a very talented developer.

ok. i’m perusing the code and here’s what i don’t understand:

[AS]prevpos = eval("_root.square"+(num-1)); // the square in front of him[/AS]
when i read this i see this:

create a new variable (prevpos) which is the square in front of the one just created.
[AS]posx += (prevpos._x-oldposx)/2; //move with delay, using the previous button[/AS]
create a new variable (posx) that takes the x position of the square in front of him and subtracts oldposx…??

(which hasn’t been declared yet – this is where i’m lost because it’s not even declared 'til a few more lines down)

so this is where i stop and get stuck. any help explaining this?

thanks. fumeng.
[AS]posy += (prevpos._y-oldposy)/2; //ditto[/AS]
[AS]_x = posx;[/AS]
[AS]_y = posy;[/AS]
[AS]oldposx = posx; //saving new position[/AS]
[AS]oldposy = posy; //ditto[/AS]