Groups | Blog | Home
all groups > flash actionscript > march 2004 >

flash actionscript : My fish die unexpectedly!



Bluefish21
3/17/2004 9:26:51 PM
Well, here's my situation. I'm relatively new to a.s., but I've managed to
begin doing what I want to do, which is make some fish swim across my screen.
You can see it somewhat work
[L=here]http://www.21bluefish.com/media_in_progress/fishies_kinda_workin.html[/L
]. Now if you clicked the link you'll see that my fish, kinda dissappear in mid
swim. That's a problem. I was hoping someone could help me figure out what I'm
doing wrong. You can download the .fla
[L=here]http://www.21bluefish.com/media_in_progress/fishies_kinda_workin.fla[/L]
.. Any help is appreciated, especially 'cause I'd like to see my fish swim not
die.I'd also like to specify that only a maximum amount of fish would be on the
page at one time. I'm sure that is an easy fix, I'm just very frazzled right
now, so I can't think very well. Again, Thanks for any help! I'll put my code
below as well as an explanation of how my movie is structured:

Ok. So my fish movie is 2 levels deep. The main is fishy_swim. The second is
fish with an instance name of fishy. The "fishy" clip is 4 frames long with 2
layers (one for object and one for as). In frames 1 and 2 the as is as
follows:(I commented so I'd remember, not so anyone would be offended, like I'm
talking down to them)

//determines width of the document
swimwidth=810;
//randomizes where the next fish will appear
fishy._x=0;
fishy._y=Math.random()*swimheight;
//determines the height of the document
swimheight=610;
//sets the behavior of each fish
magnify=Math.random();
fishy._xscale=(magnify*75)+25;
fishy._yscale=(magnify*75)+25;
step=(magnify * magnify * 2) +3;
//determines how far they can swim
fishy._x=swimwidth + 10;
gotoAndPlay(3)

then in frame 4 I have this as:
//sets variable for swim amount
fishyswim=fishy._x;
//determines if fish falls outside of area & respawns it
if ((fishyswim<=swimwidth)&(fishy<=swimheight+5)){
fishy._x = fishy._x + step;
gotoAndPlay(3);
} else {
gotoAndPlay(2);
}

that's all. I copied and pasted the fish a couple times and voila, it doesn't
work! Thanks for any help before hand!


-John


jolyon_russ
3/18/2004 12:12:55 AM
John,

I'm sorry to hear about your suicidal fish.

I've had a look at what you've done so far, its very complex with lots of MC's.

You can infact create the same effect with just 2 MC's and only 1 in the
timeline.

I have uploaded the fla
[L=here]http://www.jolyonruss.co.uk/fishies/fishies.fla[/L]

You can also view the swf
[L=here]http://www.jolyonruss.co.uk/fishies/fishies.html[/L]

I have commented the AS for you.

I suggest playing with the numbers and method for generating the random
factors, the core is there for you to adapt as you see fit.

You'll of course want to change the fish drawing to your own, if you have a MC
already set up you will need to set it's linkage so the AS can find it,
right/control-click the MC in the Library panel.

Hope this helps.

Any problems let me know.


Jolyon
Bluefish21
3/18/2004 12:57:40 AM
AddThis Social Bookmark Button