beno - wrote:
On Wed, Nov 25, 2009 at 3:36 PM, Barry Hannah <[email protected]> wrote:

Try:

public function myLeftHand(e:Event=null):void {
       //
}


The myLeftHand method is being called when an event fires, so the event
must be passed in as a method parameter. "Event=null" allows the event
to be optional - so you could also call it without dispatching an event.


This worked.
Yes, but just be aware that this technique works for this case, but would make your code more complex if your event handling function actually used the event parameter. Personally I would avoid this technique for event handlers.
Whomever told you to use enterframe to have something happen on frame 20
made a mistake. It's a valid way to get it working, I personally think
an enterframe loop is a waste of resource for that case and, more
importantly, I just don't think you're there yet. Go back to putting an
action on the timeline at frame 20.


You have a good point, of course. But I am going to do this anyway. I will
be calling this mc many times. Besides, I firmly believe that the "right"
way to do this is calling the event as I enter frames.
It's not the right way for this situation.

Enterframe operations are expensive. The more code that the flash player is executing the greater the load on the processor. For the trivial example that you have, it doesn't matter, but generally think hard if enterframe is the right solution.

In this case you are needlessly "watching" a movieclip to stop it at frame 20, when you could simply add a stop action to the timeline. Since that's all that you need to have the movieclip do, there's utterly no point in making life complicated for no reason. If you had a sophisticated behaviour (say stopping the movieclip at an arbitrary frame), I might have some sympathy with the approach, but otherwise it's complication for no reason. I have used the technique on imported MovieClips that I have no access to, so it's a useful technique but totally unnecessary here.

In programming in general and flash in particular, simplicity is preferable to complexity. Only make things as complex as they need to be for the job and no more. There is a much mentioned anagram: KISS - Keep It Simple Stupid, which makes the point most eloquently.

Frame 20 awaits your stop() command.

I think you may be learning some more things about flash but may be picking up bad habits already.

Paul
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to