用于 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 的标签
Motion 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 对象可以在多个 worker 实例之间共享其后备内存,方法是将其 shareable 属性设置为 true

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
  
从字节流中读取布尔值。
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
  
写入布尔值。
ByteArray
  
在字节流中写入一个字节。
ByteArray
  
writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
将来自指定字节数组、字节数、起始偏移(基于零的索引)字节的长度字节数序列写入字节流。
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 的任何此字节数组的副本将仍然作为单独的副本存在。

如果在此属性以前为 true 时您将其设置为了 false,则字节数组的底层内存会被立即复制到系统内存的一个新片段中。然后,此 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. 将 length 与在 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 参数,可指定压缩算法。支持的算法有:

http://www.ietf.org/rfc/rfc1950.txt 中介绍了 zlib 压缩的数据格式。

http://www.ietf.org/rfc/rfc1951.txt 中介绍了 deflate 压缩算法。

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)。必须创建一个按照压缩格式规范构建的 ByteArray,包括相应的元数据以及使用 deflate 格式获取的压缩数据。同样,若要对以 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 属性将设置为字节数组末尾。

http://www.ietf.org/rfc/rfc1951.txt 中介绍了 deflate 压缩算法。

为了使用 deflate 格式以 gzip 或 zip 等特定格式压缩 ByteArray 实例的数据,不能只调用 deflate()。必须创建一个按照压缩格式规范构建的 ByteArray,包括相应的元数据以及使用 deflate 格式获取的压缩数据。同样,为了对以 gzip 或 zip 等格式压缩的数据进行解码,对这些数据不能只调用 inflate()。首先,必须将元数据与压缩数据分离,然后才能使用 deflate 格式对压缩数据进行解压缩。

相关 API 元素

inflate

()方法 
public function inflate():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 10

使用 deflate 压缩算法将字节数组解压缩。字节数组必须已经使用相同的算法进行压缩。

在调用后,ByteArray 的 length 属性将设置为新长度。position 属性将设置为 0。

http://www.ietf.org/rfc/rfc1951.txt 中介绍了 deflate 压缩算法。

为了对使用 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

从字节流中读取布尔值。读取单个字节,如果字节非零,则返回 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 参数指定的数据字节数。从 offset 指定的位置开始,将字节读入 bytes 参数指定的 ByteArray 对象中,并将字节写入目标 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 参数的值(如在使用 01 而不是 1myTest.readMultiByte(22, "iso-8859-01") 中)可能在您的开发系统上起作用,但在其他系统上可能不起作用。在其他系统上,应用程序将使用系统的默认代码页。

返回
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 参数,可指定解压算法。支持的算法有:

http://www.ietf.org/rfc/rfc1950.txt 中介绍了 zlib 压缩的数据格式。

http://www.ietf.org/rfc/rfc1951.txt 中介绍了 deflate 压缩算法。

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

写入布尔值。根据 value 参数写入单个字节。如果为 true,则写入 1,如果为 false,则写入 0。

参数

value: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(起始偏移量为 offset,从零开始的索引)中包含 length 个字节的字节序列写入字节流。

如果省略 length 参数,则使用默认长度 0;该方法将从 offset 开始写入整个缓冲区。如果还省略了 offset 参数,则写入整个缓冲区。

如果 offsetlength 超出范围,它们将被锁定到 bytes 数组的开头和结尾。

参数

bytes:ByteArray — ByteArray 对象。
 
offset:uint (default = 0) — 从 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 类将布尔值和 pi 的双精度浮点表示形式写入字节数组。这是使用以下步骤完成的:
  1. 声明新的 ByteArray 对象实例 byteArr
  2. 写入布尔值 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 类显示为英语。