问题
I'm very new to ActionScript Workers, but I would like to know if this is possible.
From what I have read, ActionScript Workers (ASW) are like separate threads that can do more CPU intensive calculations without interrupting the Main thread (which is executing your main SWF file).
The only example I really seen kicking around was the one illustrating animation playing at a consistent rate while an ASW took care of loading or calculating some intensive math formulas.
Is the Sound API available for ActionScriptWorkers?
回答1:
(Reposted under my proper login)
They certainly can! Check out my recent blog post on exactly this:
http://flexmonkey.blogspot.co.uk/2012/09/multi-threaded-sound-synthesis-in-flex.html#!/2012/09/multi-threaded-sound-synthesis-in-flex.html
After a fair bit of tinkering, I actually generate a byte array in a background worker and then write the data back to the SampleDataEvent's data property in the primordial thread (i.e. the user interface).
I write the data from the worker from the previous SampleDataEvent while the worker generates the data for the next one - so FlashPlayer is actually doing three tasks simultaneously: offering a responsive UI, playing a tone and generating the next tone.
simon
回答2:
I'm going to venture out onto a cliff and answer YES to this question.
The release notes has a list of "non-functional" API's, I don't see any sound related classes in the list.
The following APIs will not be available from within a background worker. Any attempt to construct an instance of any of these will throw an IllegalOperationError with the message "This feature is not available within this context," the errorID will be the same in all instances, allowing developers to key off of this value.
flash.desktop.Clipboard
// calling constructor will throw; calling generalClipboard will return nullflash.desktop.NativeDragManager
// isSupported returns falseflash.desktop.Updater
// isSupported returns falseflash.display.NativeMenu
// isSupported returns falseflash.display.NativeWindow
// isSupported returns falseflash.display.ToastWindow
// can't access instance because stage.window will never be definedflash.display.Window
// can't access instance because stage.window will never be definedflash.external.ExtensionContext
// createExtensionContext() will always return null or throw an errorflash.external.ExternalInterface
// available returns falseflash.html.*
// HTMLLoader.isSupported returns falseflash.media.CameraRoll
// supportsAddBitmapData and supportsBrowseForImage returns falseflash.media.CameraUI
// isSupported returns falseflash.media.StageWebView
// isSupported returns falseflash.net.drm.*
// DRMManager.isSupported returns falseflash.printing.*
// PrintJob.isSupported returns falseflash.security.XMLSignatureValidator
// isSupported returns falseflash.system.IME
// isSupported returns falseflash.system.SystemUpdater
// calling constructor throwsflash.text.StageText
// calling constructor throws flash.ui.ContextMenu // isSupported returns falseflash.ui.GameInput
// isSupported returns falseflash.ui.Mouse
// all methods are no-ops; setting 'cursor' property is a no-op
来源:https://stackoverflow.com/questions/11902863/can-actionscript-workers-be-used-to-play-generate-sounds-in-a-separate-thread