適用於 Adobe® Flash® Platform 的 ActionScript® 3.0 參考
首頁  |  隱藏套件和類別清單 |  套件  |  類別  |  新增內容  |  索引  |  附錄  |  為什麼顯示英文?
篩選: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隱藏篩選
flash.utils 

ByteArray  - AS3

套件x

最上層
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

語言元素

全域常數
全域函數
運算子
陳述式、關鍵字和指令
特殊類型

附錄

新增內容
編譯器錯誤
編譯器警告
執行階段錯誤
移轉至 ActionScript 3
支援的字元集
僅限 MXML 標籤
移動 XML 元素
Timed Text 標籤
不建議元素清單
AccessibilityImplementation 常數
如何使用 ActionScript 範例
法律聲明
套件flash.utils
類別public class ByteArray
繼承ByteArray Inheritance Object
實作 IDataInput, IDataOutput
子類別 ByteArrayAsset

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

ByteArray 類別會提供方法和屬性,好讓讀取、寫入及使用二進位資料的動作最佳化。

注意: ByteArray 類別適用於需要在位元組層級存取資料的進階 開發人員。

記憶體內的資料是位元組的封裝陣列 (資料類型的最緊密壓縮形式),不過 ByteArray 類別的實體可由標準的 [] (陣列存取) 運算子加以操作。 使用相似於 URLStream 與 Socket 類別中的方法,也可將此實體當做記憶體內的檔案,以進行讀取和寫入。

此外,也支援 zlib、deflate 和 lzma 壓縮與解壓縮,以及 Action Message Format (AMF) 物件序列化。

ByteArray 會將它的 shareable 屬性設定為 true,以便在多個 Worker 實體之間共用它的後備記憶體。

ByteArray 類別的可能用法包括下列各項:

  • 建立自訂通訊協定以連線至伺服器。
  • 撰寫您自己的 URLEncoder/URLDecoder。
  • 撰寫您自己的 AMF/Remoting 封包。
  • 使用資料類型最佳化您的資料大小。
  • 使用從檔案載入的二進位資料。

檢視範例

相關 API 元素



公用屬性
 屬性定義自
  bytesAvailable : uint
[唯讀] 可從位元組陣列中的目前位置讀取到陣列結尾之資料的位元組數。
ByteArray
 Inheritedconstructor : Object
類別物件的參照或是特定物件實體的建構函數。
Object
  defaultObjectEncoding : uint
[靜態] 代表針對 ByteArray 類別加以編碼的預設物件,以便用於新的 ByteArray 實體。
ByteArray
  endian : String
變更或讀取資料的位元組順序,可能是 Endian.BIG_ENDIAN 或 Endian.LITTLE_ENDIAN。
ByteArray
  length : uint
ByteArray 物件的長度,以位元組為單位。
ByteArray
  objectEncoding : uint
用來決定在從 ByteArray 實體寫入或讀取資料時,應該使用 ActionScript 3.0、ActionScript 2.0 還是 ActionScript 1.0 格式。
ByteArray
  position : uint
會將 ByteArray 物件的檔案指標移動或返回到目前的位置 (以位元組為單位)。
ByteArray
  shareable : Boolean
指定位元組陣列的基礎記憶體是否為可共用。
ByteArray
公用方法
 方法定義自
  
會建立代表位元組之封裝陣列的 ByteArray 實體,如此您便可以使用此類別中的方法和屬性,讓資料的儲存與串流最佳化。
ByteArray
  
atomicCompareAndSwapIntAt(byteIndex:int, expectedValue:int, newValue:int):int
在單一不可分割的作業中,請比較這個位元組陣列中的整數值與其他整數值,如果相符,請將那些位元組替換為其他值。
ByteArray
  
atomicCompareAndSwapLength(expectedLength:int, newLength:int):int
在單一不可分割的作業中,請比較這個位元組陣列的長度與提供的值,如果相符,請變更這個位元組陣列的長度。
ByteArray
  
清除位元組陣列的內容,然後將 length 與 position 屬性重設為 0。
ByteArray
  
compress(algorithm:String):void
壓縮位元組陣列。
ByteArray
  
使用 deflate 壓縮演算法來壓縮位元組陣列。
ByteArray
 Inherited
指出物件是否有已定義的指定屬性。
Object
  
使用 deflate 壓縮演算法來解壓縮位元組陣列。
ByteArray
 Inherited
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。
Object
 Inherited
指出指定的屬性是否存在,以及是否可列舉。
Object
  
會從位元組串流讀取 Boolean 值。
ByteArray
  
會從位元組串流讀取具有正負號的位元組。
ByteArray
  
readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
會從位元組串流讀取資料位元組的數目 (由 length 參數指定)。
ByteArray
  
會從位元組串流讀取 IEEE 754 雙精度 (64 位元) 浮點數。
ByteArray
  
會從位元組串流讀取 IEEE 754 單精度 (32 位元) 浮點數。
ByteArray
  
會從位元組串流讀取具有正負號的 32 位元整數。
ByteArray
  
readMultiByte(length:uint, charSet:String):String
會使用指定的字元集,從位元組串流讀取指定之長度的多位元組字串。
ByteArray
  
會從位元組陣列讀取物件,並以 AMF 序列化格式編碼。
ByteArray
  
會從位元組串流讀取具有正負號的 16 位元整數。
ByteArray
  
會從位元組串流讀取無正負號的位元組。
ByteArray
  
會從位元組串流讀取無正負號的 32 位元整數。
ByteArray
  
會從位元組串流讀取無正負號的 16 位元整數。
ByteArray
  
會從位元組串流讀取 UTF-8 字串。
ByteArray
  
會從位元組串流讀取由 length 參數指定的 UTF-8 位元組序列,並傳回字串。
ByteArray
 Inherited
為迴圈作業設定動態屬性的可用性。
Object
  
提供可覆寫的方法,用於自訂 ByteArray 物件中值的 JSON 編碼。
ByteArray
 Inherited
傳回代表此物件的字串,根據地區特定慣例進行格式化。
Object
  
會將位元組陣列轉換為字串。
ByteArray
  
會解壓縮位元組陣列。
ByteArray
 Inherited
會傳回指定之物件的基本值。
Object
  
會寫入 Boolean 值。
ByteArray
  
會將位元組寫入位元組串流。
ByteArray
  
writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
會從指定的位元組陣列 bytes,將 length 個位元組的序列,從 offset (從零開始的索引) 個位元組之後開始寫入至位元組串流。
ByteArray
  
會將 IEEE 754 雙精度 (64 位元) 浮點數寫入位元組串流。
ByteArray
  
會將 IEEE 754 單精度 (32 位元) 浮點數寫入位元組串流。
ByteArray
  
會將具有正負號的 32 位元整數寫入位元組串流。
ByteArray
  
會使用指定的字元集,將多位元組字串寫入位元組串流。
ByteArray
  
會使用 AMF 序列化格式,將物件寫入位元組陣列。
ByteArray
  
會將 16 位元整數寫入位元組串流。
ByteArray
  
會將無正負號的 32 位元整數寫入位元組串流。
ByteArray
  
會將 UTF-8 字串寫入位元組串流。
ByteArray
  
會將 UTF-8 字串寫入位元組串流。
ByteArray
屬性詳細資訊

bytesAvailable

屬性
bytesAvailable:uint  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

可從位元組陣列中的目前位置讀取到陣列結尾之資料的位元組數。

每次存取 ByteArray 物件時,將 bytesAvailable 屬性搭配讀取方法一起使用,即可確保會讀取到有效的資料。



實作
    public function get bytesAvailable():uint

defaultObjectEncoding

屬性 
defaultObjectEncoding:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

代表針對 ByteArray 類別加以編碼的預設物件,以便用於新的 ByteArray 實體。 當您建立新的 ByteArray 實體時,該實體上的編碼會以 defaultObjectEncoding 的值開始。 defaultObjectEncoding 屬性會初始化為 ObjectEncoding.AMF3

從二進位資料寫入或讀取物件時,會使用 objectEncoding 值來決定應該使用 ActionScript 3.0、ActionScript2.0 或 ActionScript 1.0 格式。 此值是來自於 ObjectEncoding 類別的常數。



實作
    public static function get defaultObjectEncoding():uint
    public static function set defaultObjectEncoding(value:uint):void

相關 API 元素

endian

屬性 
endian:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

變更或讀取資料的位元組順序,可能是 Endian.BIG_ENDIANEndian.LITTLE_ENDIAN。預設值為 BIG_ENDIAN



實作
    public function get endian():String
    public function set endian(value:String):void

相關 API 元素

length

屬性 
length:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

ByteArray 物件的長度,以位元組為單位。

如果長度設定為大於目前長度的值,便會在位元組陣列右側填入零。

如果長度設定為小於目前長度的值,位元組陣列便會被截斷。



實作
    public function get length():uint
    public function set length(value:uint):void

objectEncoding

屬性 
objectEncoding:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

用來決定在從 ByteArray 實體寫入或讀取資料時,應該使用 ActionScript 3.0、ActionScript 2.0 還是 ActionScript 1.0 格式。 此值是來自於 ObjectEncoding 類別的常數。



實作
    public function get objectEncoding():uint
    public function set objectEncoding(value:uint):void

相關 API 元素

position

屬性 
position:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 ByteArray 物件的檔案指標移動或返回到目前的位置 (以位元組為單位)。 這是下一次呼叫讀取方法開始讀取,或是呼叫寫入方法開始寫入的點。



實作
    public function get position():uint
    public function set position(value:uint):void

shareable

屬性 
shareable:Boolean

語言版本: ActionScript 3.0
執行階段版本: Flash Player 11.5, AIR 3.5

指定位元組陣列的基礎記憶體是否為「可共用」。對於可共用的位元組陣列,所有 Worker 中參考位元組陣列的所有 ByteArray 實體會使用相同的基礎記憶體。預設值為 false,指出基礎記憶體並未在 Worker 間共用。

這個屬性也會影響執行階段如何處理這個位元組陣列 (如果它是使用 Worker.setSharedProperty() 方法或 MessageChannel.send() 方法傳遞至 Worker):

  • 不可共用:如果這個屬性是 false,當位元組陣列傳遞至 Worker 時,執行階段就會建立位元組陣列的完整複本,包括配置記憶體的子片段,以便在其中儲存重複的位元組陣列內容
  • 可共用:如果這個屬性是 true,當位元組陣列傳遞至 Worker 時,執行階段就會針對原始 ByteArray 實體與為第二個 Worker 建立的新 ByteArray 實體兩者的內容,使用與儲存緩衝區相同的基礎記憶體。在本質上,兩個 ByteArray 實體都包含相同基礎位元組陣列的參考。

同時從多個 Worker 存取共用位元組陣列的能力,可能會造成不想要的情形,例如兩個 Worker 同時操作位元組陣列的基礎記憶體。您可以使用數種機制來控制共用記憶體的存取:

  • ByteArray 類別的 atomicCompareAndSwapIntAt()atomicCompareAndSwapLength() 方法所提供的比較後替換機制
  • Mutex 和 Condition 類別 (在 flash.concurrent 套件中) 所使用的專用機制

將這個屬性設定為 true 只會影響用來將這個位元組陣列傳遞至 Worker 的後續程式碼。任何已經傳遞至 Worker 的位元組陣列版本,都會以個別版本的形式繼續存在。

如果您將這個屬性設定為 false,但先前為 true 時,位元組陣列的基礎記憶體就會立即複製到系統記憶體的新片段。從那之後,這個 ByteArray 實體就會使用新的基礎記憶體。因此,這個位元組陣列的基礎記憶體便不再與其他 Worker 共用,即使先前共用過。如果您之後將這個位元組陣列傳遞至 Worker,則會複製它的基礎記憶體,就像任何 shareable 屬性為 false 的 ByteArray 物件一樣。

預設值為 false。



實作
    public function get shareable():Boolean
    public function set shareable(value:Boolean):void

相關 API 元素

建構函式詳細資料

ByteArray

()建構函式
public function ByteArray()

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會建立代表位元組之封裝陣列的 ByteArray 實體,如此您便可以使用此類別中的方法和屬性,讓資料的儲存與串流最佳化。

方法詳細資訊

atomicCompareAndSwapIntAt

()方法
public function atomicCompareAndSwapIntAt(byteIndex:int, expectedValue:int, newValue:int):int

語言版本: ActionScript 3.0
執行階段版本: Flash Player 11.5, AIR 3.5

在單一不可分割的作業中,請比較這個位元組陣列中的整數值與其他整數值,如果相符,請將那些位元組替換為其他值。

這個方法的用途是要搭配其基礎記憶體在多個 Worker 之間共用的位元組陣列一起使用 (ByteArray 實體的 shareable 屬性為 true)。它會執行下列一連串步驟:

  1. byteIndex 引數中指定的索引 (以位元組為單位) 開始,讀取這個位元組陣列中的整數值
  2. 比較這個位元組陣列中的實際值與 expectedValue 引數中所傳遞的值
  3. 如果兩個值相等,就會將 newValue 引數中的值寫入位元組陣列中 byteIndex 參數所指定的位置,並且傳回先前包含在那些位元組中的值 (步驟 1 中讀取的值)
  4. 或者,位元組陣列中的內容不會變更,並且方法會傳回從位元組陣列讀取到的實際值

所有步驟都是在一個不可分割的硬體交易中執行的。這可保證沒有其他 Worker 的作業會在比較後替換作業期間變更位元組陣列的內容。

參數

byteIndex:int — 從中讀取要比較之整數的索引位置 (位元組),以及將 newValue 值寫入其中的索引位置 (如果比較結果相符)。這個值必須是 4 的倍數。
 
expectedValue:int — 應與位於指定索引的位元組陣列內容相符的值
 
newValue:int — 取代位於指定索引的位元組陣列內容的新值 (如果比較結果相符)

傳回值
int — 如果比較結果相符,則為位於指定之位置的先前值,或者如果實際值與預期值不符,則為位元組陣列中的實際值

擲回值
ArgumentError — 因為 byteIndex 值不是 4 的倍數,或者它是負數

相關 API 元素

atomicCompareAndSwapLength

()方法 
public function atomicCompareAndSwapLength(expectedLength:int, newLength:int):int

語言版本: ActionScript 3.0
執行階段版本: Flash Player 11.5, AIR 3.5

在單一不可分割的作業中,請比較這個位元組陣列的長度與提供的值,如果相符,請變更這個位元組陣列的長度。

這個方法的用途是要搭配其基礎記憶體在多個 Worker 之間共用的位元組陣列一起使用 (ByteArray 實體的 shareable 屬性為 true)。它會執行下列作業:

  1. 讀取 ByteArray 實體的整數 length 屬性
  2. 將長度與 expectedLength 引數中傳遞的值相比較
  3. 如果兩個值相等,就會將位元組陣列的長度變更為以 newLength 參數傳遞的值,如此,可能會增加或縮減位元組陣列的大小
  4. 或者,不會變更位元組陣列

所有步驟都是在一個不可分割的硬體交易中執行的。這可保證沒有其他 Worker 的作業會在比較後調整大小作業期間變更位元組陣列的內容。

參數

expectedLength:int — ByteArray 的預期 length 屬性值。如果指定的值與實際值相符,則會變更位元組陣列的長度。
 
newLength:int — 位元組陣列的新長度值 (如果比較成功)

傳回值
int — ByteArray 的先前 length 值,無論是否已變更

相關 API 元素

clear

()方法 
public function clear():void

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10, AIR 1.5, Flash Lite 4

清除位元組陣列的內容,然後將 lengthposition 屬性重設為 0。呼叫此方法會明確地釋放 ByteArray 實體所佔用的記憶體。

compress

()方法 
public function compress(algorithm:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

壓縮位元組陣列。壓縮整個位元組陣列。呼叫之後,ByteArray 的 length 屬性會設定為新的長度。 position 屬性設定為位元組陣列的結束。

請傳遞值 (定義於 CompressionAlgorithm 類別中) 做為 algorithm 參數,以指定壓縮演算法。支援的演算法包括下列:

zlib 壓縮資料格式於 http://www.ietf.org/rfc/rfc1950.txt 中說明。

deflate 壓縮演算法於 http://www.ietf.org/rfc/rfc1951.txt 中說明。

LZMA 壓縮演算法於 http://www.7-zip.org/7z.html 中說明。

有數種壓縮格式使用 deflate 壓縮演算法,如 zlib、gzip、一些 zip 實作等等。使用其中一個壓縮格式來壓縮資料時,除了儲存原始資料的壓縮版本之外,壓縮格式資料 (例如,.zip 檔) 還會包含中繼資料資訊。各種檔案格式中所含中繼資料類型的一些範例包含檔案名稱、檔案修改日期/時間、原始檔案大小、選擇性註解、總和檢查碼資料等等。

例如,在使用 zlib 演算法來壓縮 ByteArray 時,則產生的 ByteArray 會以特定格式結構化。有些位元組會包含有關壓縮資料的中繼資料,而有些位元組會包含原始 ByteArray 資料的實際壓縮版本。如 zlib 壓縮資料格式規格所定義,這些位元組 (即包含原始資料壓縮版本的部分) 是使用 deflate 演算法壓縮的。因此,這些位元組形同對原始 ByteArray 呼叫 compress(air.CompressionAlgorithm.DEFLATE) 之後的結果。不過,compress(air.不過,(CompressionAlgorithm.ZLIB) 的結果包含額外的中繼資料,而 compress(CompressionAlgorithm.DEFLATE) 的結果只包含原始 ByteArray 資料的壓縮版本而已。

若要使用 deflate 格式來壓縮特定格式 (如 gzip 或 zip) 的 ByteArray 實體資料,不能只呼叫 compress(CompressionAlgorithm.DEFLATE)。您必須依照壓縮格式規格,包括適當的中繼資料以及使用 deflate 格式所取得的壓縮資料,來建立結構化的 ByteArray。同樣的,若要對使用如 gzip 或 zip 等格式壓縮的資料進行解碼,不能只在該資料上呼叫 uncompress(CompressionAlgorithm.DEFLATE)。您必須先將中繼資料與壓縮資料分開,然後使用 deflate 格式,對壓縮資料進行解壓縮。

參數

algorithm:String (default = NaN) — 壓縮時使用的壓縮演算法。有效值定義為 CompressionAlgorithm 類別的常數。預設為使用 zlib 格式。呼叫 compress(CompressionAlgorithm.DEFLATE) 的效果如同呼叫 deflate() 方法。Flash Player 11.3 和 AIR 3.3 已新增對 LZMA 演算法的支援。您必須具備那些播放程式版本或更新版本,才能使用 LZMA 壓縮。

相關 API 元素

deflate

()方法 
public function deflate():void

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10, AIR 1.5, Flash Lite 4

使用 deflate 壓縮演算法來壓縮位元組陣列。壓縮整個位元組陣列。

呼叫之後,ByteArray 的 length 屬性會設定為新的長度。 position 屬性設定為位元組陣列的結束。

deflate 壓縮演算法於 http://www.ietf.org/rfc/rfc1951.txt 中說明。

若要使用 deflate 格式來壓縮特定格式 (如 gzip 或 zip) 的 ByteArray 實體資料,不能只呼叫 deflate()。您必須依照壓縮格式規格,包括適當的中繼資料以及使用 deflate 格式所取得的壓縮資料,來建立結構化的 ByteArray。同樣的,若要對使用 gzip 或 zip 等格式壓縮的資料進行解碼,不能只對資料呼叫 inflate()。您必須先將中繼資料與壓縮資料分開,然後使用 deflate 格式,對壓縮資料進行解壓縮。

相關 API 元素

inflate

()方法 
public function inflate():void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 10

使用 deflate 壓縮演算法來解壓縮位元組陣列。位元組陣列必須已經使用相同的演算法來壓縮。

呼叫之後,ByteArray 的 length 屬性會設定為新的長度。 position 屬性會設定為 0。

deflate 壓縮演算法於 http://www.ietf.org/rfc/rfc1951.txt 中說明。

若要對使用 deflate 壓縮演算法格式 (如 gzip 或 zip 格式) 壓縮的資料進行解碼,不能只對包含壓縮形式資料的 ByteArray 呼叫 inflate()。首先,您必須將以壓縮資料格式一部分的方式包含在內的中繼資料與實際壓縮資料分開。如需詳細資訊,請參閱 compress() 方法說明。


擲回值
IOError — 此資料並非有效的壓縮資料,不是以壓縮時所使用的相同壓縮演算法來壓縮。

相關 API 元素

readBoolean

()方法 
public function readBoolean():Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取 Boolean 值。 會讀取單一位元組。若該位元組不為零,則會傳回 true;否則傳回 false

傳回值
Boolean — 如果位元組不為零,則會傳回 true,否則會傳回 false

擲回值
EOFError — 沒有足夠的資料可供讀取。

readByte

()方法 
public function readByte():int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取具有正負號的位元組。

傳回的值介於 -128 到 127 的範圍之間。

傳回值
int — 介於 -128 與 127 之間的整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readBytes

()方法 
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取資料位元組的數目 (由 length 參數指定)。 位元組會讀取入由 bytes 參數所指定的 ByteArray 物件,並從 offset 所指定的位置開始,將這些位元組寫入目的 ByteArray。

參數

bytes:ByteArray — 要將資料讀入的 ByteArray 物件。
 
offset:uint (default = 0) — 應將所讀取資料寫入的 bytes 偏移量 (位置)。
 
length:uint (default = 0) — 要讀取的位元組數。 預設值為 0,會讀取所有可用的資料。


擲回值
EOFError — 沒有足夠的資料可供讀取。
 
RangeError — 提供的偏移量加上長度後的值大於單位的最大值。

readDouble

()方法 
public function readDouble():Number

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取 IEEE 754 雙精度 (64 位元) 浮點數。

傳回值
Number — 雙精度 (64 位元) 浮點數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readFloat

()方法 
public function readFloat():Number

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取 IEEE 754 單精度 (32 位元) 浮點數。

傳回值
Number — 單精度 (32 位元) 浮點數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readInt

()方法 
public function readInt():int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取具有正負號的 32 位元整數。

傳回的值介於 -2147483648 到 2147483647 的範圍之間。

傳回值
int — 介於 -2147483648 與 2147483647 之間的 32 位元具有正負號整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readMultiByte

()方法 
public function readMultiByte(length:uint, charSet:String):String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會使用指定的字元集,從位元組串流讀取指定之長度的多位元組字串。

參數

length:uint — 所要讀取之位元組串流的位元組數。
 
charSet:String — 代表字元集之字串,該字元集用於解譯位元組。 可能的字元集字串包括 "shift-jis""cn-gb""iso-8859-1",以及其他等等。 如需完整清單,請參閱「支援的字元集」

注意:如果目前的系統無法辨識 charSet 參數值,則應用程式會使用系統的預設字碼頁當做字元集。例如,charSet 參數的值 (如同在 myTest.readMultiByte(22, "iso-8859-01")) 使用 01 取代 1 在您的開發系統上可能是可行的,但在其他系統可能不可行。在其他系統上,應用程式將會使用系統的預設字碼頁。

傳回值
String — UTF-8 編碼字串。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readObject

()方法 
public function readObject():*

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組陣列讀取物件,並以 AMF 序列化格式編碼。

傳回值
* — 已還原序列化的物件。

擲回值
EOFError — 沒有足夠的資料可供讀取。

相關 API 元素

readShort

()方法 
public function readShort():int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取具有正負號的 16 位元整數。

傳回的值介於 -32768 到 32767 的範圍之間。

傳回值
int — 介於 -32768 與 32767 之間的 16 位元具有正負號整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readUnsignedByte

()方法 
public function readUnsignedByte():uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取無正負號的位元組。

傳回的值介於 0 到 255 的範圍之間。

傳回值
uint — 介於 0 與 255 之間的 32 位元無正負號整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readUnsignedInt

()方法 
public function readUnsignedInt():uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取無正負號的 32 位元整數。

傳回的值介於 0 到 4294967295 的範圍之間。

傳回值
uint — 介於 0 與 4294967295 之間的 32 位元無正負號整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readUnsignedShort

()方法 
public function readUnsignedShort():uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取無正負號的 16 位元整數。

傳回的值介於 0 到 65535 的範圍之間。

傳回值
uint — 介於 0 與 65535 之間的 16 位元無正負號整數。

擲回值
EOFError — 沒有足夠的資料可供讀取。

readUTF

()方法 
public function readUTF():String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取 UTF-8 字串。 會假定此字串的前置詞為無正負號的短整數,以指示以位元組為單位的長度。

傳回值
String — UTF-8 編碼字串。

擲回值
EOFError — 沒有足夠的資料可供讀取。

相關 API 元素

readUTFBytes

()方法 
public function readUTFBytes(length:uint):String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從位元組串流讀取由 length 參數指定的 UTF-8 位元組序列,並傳回字串。

參數

length:uint — 無正負號的短整數,指出 UTF-8 位元組的長度。

傳回值
String — 字串,由指定之長度的 UTF-8 位元組所構成。

擲回值
EOFError — 沒有足夠的資料可供讀取。

toJSON

()方法 
public function toJSON(k:String):*

語言版本: ActionScript 3.0
執行階段版本: Flash Player 11, AIR 3, Flash Lite 4

提供可覆寫的方法,用於自訂 ByteArray 物件中值的 JSON 編碼。

JSON.stringify() 方法會在周遊的每個物件上尋找 toJSON() 方法。如果找到 toJSON() 方法,JSON.stringify() 就會在每次遇到值時呼叫方法,以便傳入與值配對的索引鍵。

ByteArray 提供的 toJSON() 預設實作只會傳回類別的名稱。由於任何 ByteArray 的內容都需要解譯,因此,想要將 ByteArray 物件匯出至 JSON 的用戶端必須提供自己的實作。提供的方式是,重新定義類別原型上的 toJSON() 方法。

toJSON() 方法可以傳回任何類型的值。如果傳回物件,stringify() 就會遞迴至該物件。如果 toJSON() 傳回字串,stringify() 不會遞迴,而是繼續它的周遊。

參數

k:StringJSON.stringify() 在這個物件周遊中所遇到索引鍵值配對的索引鍵

傳回值
* — 類別名稱字串。

相關 API 元素

toString

()方法 
public function toString():String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將位元組陣列轉換為字串。 如果陣列中的資料是以 Unicode 位元組順序標記開始,應用程式在轉換為字串時便會遵循該標記。如果 System.useCodePage 設定為 true,應用程式便會在轉換時將陣列中的資料當成是目前系統字碼頁中的資料來處理。

傳回值
String — 位元組陣列的字串形式。

uncompress

()方法 
public function uncompress(algorithm:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會解壓縮位元組陣列。呼叫之後,ByteArray 的 length 屬性會設定為新的長度。 position 屬性會設定為 0。

位元組陣列必須已經使用與不壓縮相同的演算法來壓縮。請傳遞值 (定義於 CompressionAlgorithm 類別中) 做為 algorithm 參數,以指定不壓縮演算法。支援的演算法包括下列:

zlib 壓縮資料格式於 http://www.ietf.org/rfc/rfc1950.txt 中說明。

deflate 壓縮演算法於 http://www.ietf.org/rfc/rfc1951.txt 中說明。

LZMA 壓縮演算法於 http://www.7-zip.org/7z.html 中說明。

若要對使用 deflate 壓縮演算法 (如 gzip 或 zip 格式) 格式壓縮的資料進行解碼,不能只在包含壓縮形式資料的 ByteArray 上呼叫 uncompress(CompressionAlgorithm.DEFLATE)。首先,您必須將以壓縮資料格式一部分的方式包含在內的中繼資料與實際壓縮資料分開。如需詳細資訊,請參閱 compress() 方法說明。

參數

algorithm:String (default = NaN) — 解壓縮時使用的壓縮演算法。這必須是壓縮資料時所使用的相同壓縮演算法。有效值定義為 CompressionAlgorithm 類別的常數。預設為使用 zlib 格式。Flash Player 11.3 和 AIR 3.3 已新增對 LZMA 演算法的支援。您必須具備那些播放程式版本或更新版本,才能使用 LZMA。


擲回值
IOError — 此資料並非有效的壓縮資料,不是以壓縮時所使用的相同壓縮演算法來壓縮。

相關 API 元素

writeBoolean

()方法 
public function writeBoolean(value:Boolean):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會寫入 Boolean 值。 會根據 value 參數寫入單一位元組;如果為 true 則為 1,如果為 false 則為 0。

參數

value:Boolean — Boolean 值,用以決定寫入的位元組。如果此參數為 true,此方法便會寫入 1;如果為 false,此方法便會寫入 0。

writeByte

()方法 
public function writeByte(value:int):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將位元組寫入位元組串流。

會使用此參數的低 8 位元。 會忽略高的 24 位元。

參數

value:int — 32 位元整數。 會將低 8 位元寫入位元組串流中。

writeBytes

()方法 
public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會從指定的位元組陣列 bytes,將 length 個位元組的序列,從 offset (從零開始的索引) 個位元組之後寫入至位元組串流。

如果省略 length 參數,便會使用 0 的預設長度;從 offset 位置開始寫入整個緩衝區。如果也省略 offset 參數,便會寫入整個緩衝區。

如果 offsetlength 超出範圍,這兩者便會固定至 bytes 陣列的開頭與結尾。

參數

bytes:ByteArray — ByteArray 物件。
 
offset:uint (default = 0) — 從零開始的索引,指出要在陣列中開始寫入的位置。
 
length:uint (default = 0) — 無正負號的整數,指出要在緩衝區中寫入的長度。

writeDouble

()方法 
public function writeDouble(value:Number):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 IEEE 754 雙精度 (64 位元) 浮點數寫入位元組串流。

參數

value:Number — 雙精度 (64 位元) 浮點數。

writeFloat

()方法 
public function writeFloat(value:Number):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 IEEE 754 單精度 (32 位元) 浮點數寫入位元組串流。

參數

value:Number — 單精度 (32 位元) 浮點數。

writeInt

()方法 
public function writeInt(value:int):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將具有正負號的 32 位元整數寫入位元組串流。

參數

value:int — 要寫入位元組串流的整數。

writeMultiByte

()方法 
public function writeMultiByte(value:String, charSet:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會使用指定的字元集,將多位元組字串寫入位元組串流。

參數

value:String — 要寫入的字串值。
 
charSet:String — 表示要使用之字元集的字串。 可能的字元集字串包括 "shift-jis""cn-gb""iso-8859-1",以及其他等等。 如需完整清單,請參閱「支援的字元集」

writeObject

()方法 
public function writeObject(object:*):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會使用 AMF 序列化格式,將物件寫入位元組陣列。

參數

object:* — 要序列化的物件。

相關 API 元素

writeShort

()方法 
public function writeShort(value:int):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 16 位元整數寫入位元組串流。 會使用此參數的低 16 位元。 會忽略高的 16 位元。

參數

value:int — 32 位元整數,其中低 16 位元會寫入位元組串流。

writeUnsignedInt

()方法 
public function writeUnsignedInt(value:uint):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將無正負號的 32 位元整數寫入位元組串流。

參數

value:uint — 要寫入位元組串流的無正負號整數。

writeUTF

()方法 
public function writeUTF(value:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 UTF-8 字串寫入位元組串流。 會先寫入 UTF-8 字串的長度 (以位元組為單位,16 位元整數),後面緊接著表示字串之字元的位元組。

參數

value:String — 要寫入的字串值。


擲回值
RangeError — 如果長度大於 65535 的話。

writeUTFBytes

()方法 
public function writeUTFBytes(value:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 UTF-8 字串寫入位元組串流。 類似 writeUTF() 方法,但是 writeUTFBytes() 不以 16 位元長度的字做為字串前置詞。

參數

value:String — 要寫入的字串值。

ByteArrayExample.as

下列範例會使用 ByteArrayExample 類別,將 Boolean 和 pi 的雙精度浮點表示法寫入到位元組陣列。 這是透過下列步驟完成:
  1. 宣告新的 ByteArray 物件實體 byteArr
  2. 寫入與 Boolean false 相等的位元組值,然後檢查長度並將它讀回。
  3. 寫入數學 pi 值的相等雙精度浮點值。
  4. 讀回寫入位元組陣列之九個位元組中的每一個位元組。

注意: 當針對某個位元組呼叫 trace() 時,它會列印儲存於位元組陣列中的相同十進位位元組值。

請注意程式碼區段會如何加入到結尾來檢查是否有檔案結尾錯誤,以確保不會讀取超過位元組串流結尾的資料。

package {
    import flash.display.Sprite;
    import flash.utils.ByteArray;
    import flash.errors.EOFError;

    public class ByteArrayExample extends Sprite {        
        public function ByteArrayExample() {
            var byteArr:ByteArray = new ByteArray();

            byteArr.writeBoolean(false);
            trace(byteArr.length);            // 1
            trace(byteArr[0]);            // 0

            byteArr.writeDouble(Math.PI);
            trace(byteArr.length);            // 9
            trace(byteArr[0]);            // 0
            trace(byteArr[1]);            // 64
            trace(byteArr[2]);            // 9
            trace(byteArr[3]);            // 33
            trace(byteArr[4]);            // 251
            trace(byteArr[5]);            // 84
            trace(byteArr[6]);            // 68
            trace(byteArr[7]);            // 45
            trace(byteArr[8]);            // 24
            
            byteArr.position = 0;

            try {
                trace(byteArr.readBoolean() == false); // true
            } 
            catch(e:EOFError) {
                trace(e);           // EOFError: Error #2030: End of file was encountered.
            }
            
            try {
                trace(byteArr.readDouble());        // 3.141592653589793
            }
            catch(e:EOFError) {
                trace(e);           // EOFError: Error #2030: End of file was encountered.
            }
            
            try {
                trace(byteArr.readDouble());
            } 
            catch(e:EOFError) {
                trace(e);            // EOFError: Error #2030: End of file was encountered.
            }
        }
    }
}




[ X ]為什麼顯示英文?
「ActionScript 3.0 參考」的內容是以英文顯示

並非所有「ActionScript 3.0 參考」的內容都翻譯為所有語言。當語言元素未翻譯時,就會以英文顯示。例如,ga.controls.HelpBox 類別並沒有翻譯為任何語言。因此在參考的繁體中文版本中,ga.controls.HelpBox 類別就會以英文顯示。