some code will execute whether the movieclip "plays"/"is displayed" or not. eg, all code in named functions, no matter their location, are defined and ready to execute in frame 1 of the main timeline.
The code is not executed in frame 1. It is executed when jumping later in the timeline where the clip doesn't exist. Like jumping over it. But the load event is triggerd even the frame where the clip exists never was active.
i didn't say the code would execute in frame 1.
Ahh ok sorry, is misunderstood that.
I also noticed that functions inside the load event are defined at runtime. After programming in as3 for some time as2 becomes a bit odd to me
oh, it's definitely odd. but that behavior only applies to named functions so, if it's a problem, you can use anonymous functions:
f1 will be defined and ready to execute even if it's on a frame that's not entered by the playhead. it's ready as soon as frame 1 of the timeline in which it's located plays. ie, that code on frame 2000 of the main timeline will be ready to execute in frame 1 of the main timeline long before frame 2000 plays. in fact, frame 2000 doesn't need to ever play.
f2 will only be defined when the frame that contains its code plays. if you try and execute f2() before its frame plays, you will get an error. in fact, if you try and call f2() in the line above its definition, you will get an error.
p.s. i notice an error in my first message. it says, "eg, all code in named functions, no matter their location, are defined and ready to execute in frame 1 of the main timeline." this is accurate: all named functions are ready as soon as frame 1 of the timeline in which it's located plays.
And if you put the first version (function f1()) into a "load" ClipEvent it will act like version (f2 = function). I put a if condition around my code for not executing when in a different frame and tried to execute a function that was later in the script but it was undefined. So I had to put the execute code in the 'if' branch and the functions outside.
I was expecting functions to work like you just described.
The funny thing was that the code in the load event isn't executed when the playhead is earlier in the timeline but only if it is later in timeline. Never saw that after years of programming as2.
you can't next named functions and there's never any reason to nest a named function.