开发者

Is it preferred to import a class (ex. import flash.events.MouseEvent ) instead of the entire contents of a package (ex. import flash.events.*)

开发者 https://www.devze.com 2023-04-10 11:47 出处:网络
Is therebenefit to specifying which class, function or namespace you intend to use at the beginning开发者_如何转开发 of the code?the reference says:

Is there benefit to specifying which class, function or namespace you intend to use at the beginning开发者_如何转开发 of the code?


the reference says:

If you import a class but do not use it in your script, the class is not exported as part of the SWF file. This means you can import large packages without being concerned about the size of the SWF file; the bytecode associated with a class is included in a SWF file only if that class is actually used. One disadvantage of importing classes that you do not need is that you increase the likelihood of name collisions.

however, it's much more convinient (for me) to have an exact list of classes that are used in the code that follows


It only affects compile time, and not to any great extent as far as I've noticed.

One benefit is that your import statements act as a "definition" of what external classes are used, but personally I don't really find that useful.


well, if you call the specified object more than once in your code you have the benefit of saving keystrokes. also, if the class is moved to a different folder it's much easier to simply update only one import line. it's also cleaner looking, in my opinion.

i thought i tried writing the path once in my AS3 code and it wouldn't compile. perhaps it was a setting i have but i was under the impression that this was not possible in AS3.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号