As3.0 MVC - How to Pass Model Class to Animated MovieClips?

154 views Asked by At

I know I know. Actionscript 3. OOP. Never use timeline code. But there are actually sometimes where it is ok to use timeline code. As an intermediate programmer learned mvc and opp principles and wisdom I vowed to never again use timeline code. Indeed, I don't use it at all in the main timeline of an fla file.

However, after working with some hardcore Flash animators on a game recently I want to argue that coding in the timeline of animated movieclips is acceptable if used properly. One obvious thing is the stop(); command. I use it alot actually. I never use gotoAndStop() only because thinking "go to and play" in my head makes me feel so giddy. Anyway, less common things to put in frames are gotoAndPlay("anim_begin") to make something loop. It seems that the rickety "addFrameScript" method of as3 has become unreliable at least in my experience, so I always add to a frame this line to trigger things in the code:

dispatchEvent(new Event("THING_THAT_HAPPENED", true));

Anyway, now I am making a game where the foot of the player, basically a nested movieclip, needs to check in each frame whether it is colliding with an array of balls that are held in the Model.as class in the code for the project.

Is there a way for me to "inject" the data in my model class into a movieclip's frame so that this array is available for me to use in the timeline here? Or if you can think of a better way to do it that is appreciated too. Thanks, Jim

1

There are 1 answers

0
Cadin On

I'm not sure about sending data to a frame script like that, but typically I wouldn't have a player object handle its own collision checking anyway. Chances are multiple things need to happen when a collision occurs (the player changes animation state, but the ball trajectory probably changes too, the score updates, etc).

So it usually works better to have a controller do the collision test. It can have a reference to the ball array and to the foot MovieClip.

Does that help?