Recommendations for working with external function files in AS3 / CS5

The Flash developer recently told me that I respect that using

include "functions_file.as"; 

is not a suitable way to import a list of functions into an AS3 document, Flash CS5.

We are not talking about objects and packages, but simply a list of functions.

So what is the best way to do this?

+4
source share
2 answers

Your various functions belong to their separate files, as do your classes:

 package foo.bar { public function baz(fizz, buzz) { return fizz * buzz + 7; } } 

And then use the import directive, as for the class:

 import foo.bar.baz; 

The important difference is that the include directive will execute the file each time it is called, which will essentially rewrite the functions each time it is called.

+2
source

As a rule, in 99.9% of situations I agree.

I'm going to be the opposite, though, and I say that there is at least one valid use case for this, since you can specify a set of ways to behave on an arbitrary frame in many different library symbols without these symbols, you must definitely define their own class. I would say that the restriction on this would be something like:

 import complete.as // inside complete.as this.dispatchEvent(new Event(Event.COMPLETE, true)); this.stop(); // Note : dispatchEvent and stop are // the only function calls I'd feel // comfortable putting on a keyframe script. 

This is especially convenient if the clips in question should not (or cannot) share relationships in the inheritance tree, but all of them require the execution of a certain specific set of code in a given frame. If you save this code in a separate .as file, and then you need to change it later (perhaps to add or remove this dispatch call), you do not need to track each symbol of the library and change them manually. Just change the attached .as file.

0
source

Source: https://habr.com/ru/post/1343693/


All Articles