Flash ActionScript 3 capabilities lacking in ActionScript 2

我的未来我决定 提交于 2020-01-11 07:32:08

问题


Ever since Adobe introduced ActionScript 3 with Flash Player 9, many of us have been slow to switch over. In short I'd like to know what AS3 as a framework can do, that is simply impossible or significantly difficult in AS2. I'm not talking about readymade components, but built-in classes such as for web remoting, binary data manipulation, XML handling, etc.


回答1:


well, actually, AS3 is a language, not a framework ... the flash player API has framework like traits ... but ok, let's not argue about terminology ... so what's cool in flash player 9 (other than things that were mentioned already)?

  • a couple of language features making your life A LOT easier : method closures (no need for Delegate), optional arguments (saves a lot of time compared to AS2 optional arguments, which are rather a hack), instance scope resolution (you can access members of an instance from within an anonymous function declared in a method of that instances, so no need for var self = this;)
  • general API design : API is much cleaner, sensibly packaged, has constants properly defined (in many classes like flash.filters.BitmapFilterType), and exposes quite a lot more things, and offers proper error handling
  • package flash.net:
    • Socket: real sockets, instead of XML sockets ... this allows any TCP based protocol to be implemented
    • URLStream: this is actually quite powerfull, but personally, i always use sockets instead
  • package flash.display: much cleaner, much more consistent, much more granular (and thus reducing overhead) ... also, you can finally take objects away off the display list, change their parent etc. ... input events are no longer handled through one single callback (which sometimes is a hell of a limitation), they are triggered in a sensible manner (on objects, that have focus), they are triggered in nested InteractiveObjects ... and then event bubbling on the display list ...
    • Loader::loadBytes: allows to generate swf at runtime with ActionScript and load them into the player directly, as well as manual caching
    • Stage::frameRate: finally, you can change it at runtime
    • DisplayObject::getBounds & DisplayObject::getRect: much better, than fiddling around with this incredibly stupid return value of the AS2 equivalent ...
  • package flash.events: partially mentioned above, in conjuction with the DisplayObjectModel, it is much cleaner, much more powerful, very reusable ... well done, really ...
  • package flash.utils:
    • ByteArray: manipulation of binary data in reasonable time ... this allows JPG or PNG compression, PDF creation on client side, and so on
    • Dictionary: allows mapping objects to objects ... this can come in very handy (you could hack that into AS2, but that wasn't your question, right?) ... for example, this is great for creating sets, or mapping objects to handlers, etc.
    • Proxy: the proxy class is so damn powerful and so much fun to play with, really ... use it for proxies, collections, AOP, etc. ...
    • Timer: ok, now this can quite easily be reimplemented in AS2, but apart from that, i think it's much cleaner than fiddling arount with setInterval ...
  • package flash.text:
    • TextField: much bigger API, allows many cool things, as getting character/line metrics, etc. ...
    • Font.registerFont: allows embedding fonts at runtime
    • overall design is much cleaner and powerful
  • package flash.sampler: this is REALLY helpful, when trying to find bottlenecks
  • package flash.media: much better API, notably SoundChannel and SoundTransform are really helpful ...

note that event model and diplay list can be reimplemented in AS2 at additional performance cost, but i think it was about built-in features ...

i think, that's about it ...

greetz

back2dos




回答2:


A big plus is speed. AS3 is much faster than AS2. This obviously allows you to do more intensive coding/animation.

Then there's also the argument that everything new that is being introduced (built in 3D, pixel bender, etc) is targeted at AS3, so if you're sticking with AS2, you're already 3 or so years behind "the cutting edge".




回答3:


As a list:

  • Local load & save
  • flash.text.engine and all its new capabilities (its quite big)
  • native 2.5D (Matrix3D, PerspectiveProjection, etc)
  • custom URL Requests
  • Binary data Manipulation (it was quite trivial in AS2)
  • "Fast" Bitmap Manipulation (it allows much more than AS2)
  • Custom Filters (Pixel Bender)
  • the new drawing API has a few new capabilities
  • E4X XML
  • Alchemy
  • Inversed Kinematics
  • DRM media (not sure if it was possible in AS2)

I'm probably forgetting quite a few...




回答4:


Aside from the move towards a more java like OO approach (more strict), one of the many things missing is the ability to turn the stage into a bitmap. You have more control over where movie clips are sitting using a display list. An example would be, if clip A contains clip B, you can, through code, rearrange B so it contains A. There's lots of stuff like that which allows for much more control. XML is easier to use, and the event handling is more consistent with modern languages. One cool feature is the ability to send an array of bytes to a server side script, which allows you to save jpg, gif and png onto a server directly from flash.

There are more examples but I can't think of any at the moment




回答5:


Peter Elst has a nice video podcast introducing the features available in ActionScript3



来源:https://stackoverflow.com/questions/1116598/flash-actionscript-3-capabilities-lacking-in-actionscript-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!