ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Hide Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes

Language Reference only
Filters: AIR 32.0 and earlier, Flash Player 32.0 and earlier, Flash Lite 4
Flex 4.6 and earlier, Flash Pro CS6 and earlier
Hide Filters
flash.net 

LocalConnection  - AS3

Packagesx

Top Level
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

Language Elements

Global Constants
Global Functions
Operators
Statements, Keywords & Directives
Special Types

Appendixes

What's New
Compiler Errors
Compiler Warnings
Run-Time Errors
Migrating to ActionScript 3
Supported Character Sets
MXML Only Tags
Motion XML Elements
Timed Text Tags
List of deprecated elements
Accessibility Implementation Constants
How to Use ActionScript Examples
Legal notices
Packageflash.net
Classpublic class LocalConnection
InheritanceLocalConnection Inheritance EventDispatcher Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

The LocalConnection class lets you create a LocalConnection object that can invoke a method in another LocalConnection object. The communication can be:
  • Within a single SWF file
  • Between multiple SWF files
  • Between content (SWF-based or HTML-based) in AIR applications
  • Between content (SWF-based or HTML-based) in an AIR application and SWF content running in a browser

AIR profile support: This feature is supported on all desktop operating systems and on all AIR for TV devices, but is not supported on mobile devices. You can test for support at run time using the LocalConnection.isSupported property. See AIR Profile Support for more information regarding API support across multiple profiles.

Note: AIR for TV devices support communication only between SWF-based content in AIR applications.

Local connections enable this kind of communication between SWF files without the use of fscommand() or JavaScript. LocalConnection objects can communicate only among files that are running on the same client computer, but they can be running in different applications — for example, a file running in a browser and a SWF file running in Adobe AIR.

LocalConnection objects created in ActionScript 3.0 can communicate with LocalConnection objects created in ActionScript 1.0 or 2.0. The reverse is also true: LocalConnection objects created in ActionScript 1.0 or 2.0 can communicate with LocalConnection objects created in ActionScript 3.0. Flash Player handles this communication between LocalConnection objects of different versions automatically.

There are three ways to add callback methods to a LocalConnection object:

  • Subclass the LocalConnection class and add methods.
  • Set the LocalConnection.client property to an object that implements the methods.
  • Create a dynamic class that extends LocalConnection and dynamically attach methods.

To understand how to use LocalConnection objects to implement communication between two files, it is helpful to identify the commands used in each file. One file is called the receiving file; it is the file that contains the method to be invoked. The receiving file must contain a LocalConnection object and a call to the connect() method. The other file is called the sending file; it is the file that invokes the method. The sending file must contain another LocalConnection object and a call to the send() method.

Your use of send() and connect() differs depending on whether the files are in the same domain, in different domains with predictable domain names, or in different domains with unpredictable or dynamic domain names. The following paragraphs explain the three different situations, with code samples for each.

Same domain. This is the simplest way to use a LocalConnection object, to allow communication only between LocalConnection objects that are located in the same domain, because same-domain communication is permitted by default. When two files from the same domain communicate, you do not need to implement any special security measures, and you simply pass the same value for the connectionName parameter to both the connect() and send() methods:

Loading from the same domain

// receivingLC is in http://www.domain.com/receiving.swf
receivingLC.connect('myConnection');

// sendingLC is in http://www.domain.com/sending.swf
// myMethod() is defined in sending.swf
sendingLC.send('myConnection', 'myMethod');

Different domains with predictable domain names. When two SWF files from different domains communicate, you need to allow communication between the two domains by calling the allowDomain() method. You also need to qualify the connection name in the send() method with the receiving LocalConnection object's domain name:

Loading from separate domains

// receivingLC is in http://www.domain.com/receiving.swf
receivingLC.allowDomain('www.anotherdomain.com');
receivingLC.connect('myConnection');

// sendingLC is in http://www.anotherdomain.com/sending.swf
sendingLC.send('www.domain.com:myConnection', 'myMethod');

Different domains with unpredictable domain names. Sometimes, you might want to make the file with the receiving LocalConnection object more portable between domains. To avoid specifying the domain name in the send() method, but to indicate that the receiving and sending LocalConnection objects are not in the same domain, precede the connection name with an underscore (_), in both the connect() and send() calls. To allow communication between the two domains, call the allowDomain() method and pass the domains from which you want to allow LocalConnection calls. Alternatively, pass the wildcard (*) argument to allow calls from all domains:

Loading from unknown domain names

// receivingLC is in http://www.domain.com/receiving.swf
receivingLC.allowDomain('*');
receivingLC.connect('_myConnection');

// sendingLC is in http://www.anotherdomain.com/sending.swf
sendingLC.send('_myConnection', 'myMethod');

From Flash Player to an AIR application. A LocalConnection object created in the AIR application sandbox uses a special string as it's connection prefix instead of a domain name. This string has the form: app#appID.pubID where appID is the application ID and pubID is the publisher ID of the application. (Only include the publisher ID if the AIR application uses a publisher ID.) For example, if an AIR application has an application ID of, "com.example", and no publisher ID, you could use: app#com.example:myConnection as the local connection string. The AIR application also must call the allowDomain() method, passing in the calling SWF file's domain of origin:

Flash Player to AIR connection

// receivingLC is an AIR application with app ID = com.example (and no publisher ID)
receivingLC.allowDomain('www.domain.com');
receivingLC.connect('myConnection');

// sendingLC is in http://www.domain.com/sending.swf
sendingLC.send('app#com.example:myConnection', 'myMethod');

Note: If an AIR application loads a SWF outside the AIR application sandbox, then the rules for establishing a local connection with that SWF are the same as the rules for establishing a connection with a SWF running in Flash Player.

From an AIR application to Flash Player. When an AIR application communicates with a SWF running in the Flash Player runtime, you need to allow communication between the two by calling the allowDomain() method and passing in the AIR application's connection prefix. For example, if an AIR application has an application ID of, "com.example", and no publisher ID, you could pass the string: app#com.example to the allowDomain() method. You also need to qualify the connection name in the send() method with the receiving LocalConnection object's domain name (use "localhost" as the domain for SWF files loaded from the local file system):

AIR to Flash Player communication

// receivingLC is in http://www.domain.com/receiving.swf
receivingLC.allowDomain('app#com.example');
receivingLC.connect('myConnection');

// sendingLC is an AIR application with app ID = com.example (and no publisher ID)
sendingLC.send('www.domain.com:myConnection', 'myMethod');

From an AIR application to another AIR application. To communicate between two AIR applications, you need to allow communication between the two by calling the allowDomain() method and passing in the sending AIR application's connection prefix. For example, if the sending application has an application ID of, "com.example", and no publisher ID, you could pass the string: app#com.example to the allowDomain() method in the receiving application. You also need to qualify the connection name in the send() method with the receiving LocalConnection object's connection prefix:

AIR to AIR communication

// receivingLC is an AIR application with app ID = com.sample (and no publisher ID)
receivingLC.allowDomain('app#com.example');
receivingLC.connect('myConnection');

// sendingLC is an AIR application with app ID = com.example (and no publisher ID)
sendingLC.send('app#com.sample:myConnection', 'myMethod');

You can use LocalConnection objects to send and receive data within a single file, but this is not a typical implementation.

For more information about the send() and connect() methods, see the discussion of the connectionName parameter in the LocalConnection.send() and LocalConnection.connect()entries. Also, see the allowDomain() and domain entries.

View the examples

More examples

Related API Elements



Public Properties
 PropertyDefined By
  client : Object
Indicates the object on which callback methods are invoked.
LocalConnection
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  domain : String
[read-only] A string representing the domain of the location of the current file.
LocalConnection
  isPerUser : Boolean
Indicates whether the LocalConnection object is scoped to the current user (true) or is globally accessible to all users on the computer (false).
LocalConnection
  isSupported : Boolean
[static] [read-only] The isSupported property is set to true if the LocalConnection class is supported on the current platform, otherwise it is set to false.
LocalConnection
Public Methods
 MethodDefined By
  
Creates a LocalConnection object.
LocalConnection
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
Specifies one or more domains that can send LocalConnection calls to this LocalConnection instance.
LocalConnection
  
Specifies one or more domains that can send LocalConnection calls to this LocalConnection object.
LocalConnection
  
Closes (disconnects) a LocalConnection object.
LocalConnection
  
connect(connectionName:String):void
Prepares a LocalConnection object to receive commands that are sent from a send() command (from the sending LocalConnection object).
LocalConnection
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
  
send(connectionName:String, methodName:String, ... arguments):void
Invokes the method named methodName on a connection that was opened with the connect(connectionName) method (in the receiving LocalConnection object).
LocalConnection
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
  Dispatched when an exception is thrown asynchronously — that is, from native asynchronous code.LocalConnection
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
  Dispatched if a call to LocalConnection.send() attempts to send data to a different security sandbox.LocalConnection
  Dispatched when a LocalConnection object reports its status.LocalConnection
Property Detail

client

property
client:Object

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Indicates the object on which callback methods are invoked. The default object is this, the local connection being created. You can set the client property to another object, and callback methods are invoked on that other object.



Implementation
    public function get client():Object
    public function set client(value:Object):void

Throws
TypeError — The client property must be set to a non-null object.

More examples

domain

property 
domain:String  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

A string representing the domain of the location of the current file.

In content running in the application security sandbox in Adobe AIR (content installed with the AIR application), the runtime uses the string app# followed by the application ID for the AIR application (defined in the application descriptor file) in place of the superdomain. For example a connectionName for an application with the application ID com.example.air.MyApp connectionName resolves to "app#com.example.air.MyApp:connectionName".

In SWF files published for Flash Player 9 or later, the returned string is the exact domain of the file, including subdomains. For example, if the file is located at www.adobe.com, this command returns "www.adobe.com".

If the current file is a local file residing on the client computer running in Flash Player, this command returns "localhost".

The most common ways to use this property are to include the domain name of the sending LocalConnection object as a parameter to the method you plan to invoke in the receiving LocalConnection object, or to use it with LocalConnection.allowDomain() to accept commands from a specified domain. If you are enabling communication only between LocalConnection objects that are located in the same domain, you probably don't need to use this property.



Implementation
    public function get domain():String

Related API Elements

isPerUser

property 
isPerUser:Boolean

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.0.32, AIR 1.5.2

Indicates whether the LocalConnection object is scoped to the current user (true) or is globally accessible to all users on the computer (false). This property only affects content running on Mac OS X; other platforms ignore this parameter. Connections on Windows and Linux operating systems are always per-user.

In Flash Player 10.0.22 and earlier, and in AIR 1.5.1 and earlier, all LocalConnection objects on Mac OS X have a global scope. Always set this property to true, unless you need to preserve compatibility with previous versions. In future releases, the default value of this property might change to true.

The default value is false.



Implementation
    public function get isPerUser():Boolean
    public function set isPerUser(value:Boolean):void

isSupported

property 
isSupported:Boolean  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2

The isSupported property is set to true if the LocalConnection class is supported on the current platform, otherwise it is set to false.



Implementation
    public static function get isSupported():Boolean
Constructor Detail

LocalConnection

()Constructor
public function LocalConnection()

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Creates a LocalConnection object. You can use LocalConnection objects to enable communication between different files that are running on the same client computer.

Related API Elements

Method Detail

allowDomain

()method
public function allowDomain(... domains):void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Specifies one or more domains that can send LocalConnection calls to this LocalConnection instance.

You cannot use this method to let files hosted using a secure protocol (HTTPS) allow access from files hosted in nonsecure protocols; you must use the allowInsecureDomain() method instead.

You may want to use this method so that a child file from a different domain can make LocalConnection calls to the parent file, without knowing the final domain from which the child file will come. This can happen, for example, when you use load-balancing redirects or third-party servers. In this situation, you can use the url property of the LoaderInfo object used with the load, to get the domain to use with the allowDomain() method. For example, if you use a Loader object to load a child file, once the file is loaded, you can check the contentLoaderInfo.url property of the Loader object, and parse the domain out of the full URL string. If you do this, make sure that you wait until the file is loaded, because the contentLoaderInfo.url property will not have its final, correct value until the file is completely loaded.

The opposite situation can also occur: you might create a child file that wants to accept LocalConnection calls from its parent but doesn't know the domain of its parent. In this situation, implement this method by checking whether the domain argument matches the domain of the loaderInfo.url property in the loaded file. Again, you must parse the domain out of the full URL from loaderInfo.url. In this situation, you don't have to wait for the parent file to load; the parent will already be loaded by the time the child loads.

When using this method, consider the Flash Player security model. By default, a LocalConnection object is associated with the sandbox of the file that created it, and cross-domain calls to LocalConnection objects are not allowed unless you call the LocalConnection.allowDomain() method in the receiving file. However, in Adobe AIR, content in the application security sandbox (content installed with the AIR application) are not restricted by these security limitations.

For more information related to security, see the Flash Player Developer Center Topic: Security.

Note: The allowDomain() method has changed from the form it had in ActionScript 1.0 and 2.0. In those earlier versions, allowDomain was a callback method that you implemented. In ActionScript 3.0, allowDomain() is a built-in method of LocalConnection that you call. With this change, allowDomain() works in much the same way as flash.system.Security.allowDomain().

Parameters

... domains — One or more strings that name the domains from which you want to allow LocalConnection calls. This parameter has two special cases:
  • You can specify a wildcard character "*" to allow calls from all domains.
  • You can specify the string "localhost" to allow calls to this file from files that are installed locally. Flash Player 8 introduced security restrictions on local files. By default, a SWF file running in Flash Player that is allowed to access the Internet cannot also have access to the local file system. In Flash Player, if you specify "localhost", any local SWF file can access this SWF file.


Throws
ArgumentError — All parameters specified must be non-null strings.

More examples

Related API Elements

allowInsecureDomain

()method 
public function allowInsecureDomain(... domains):void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Specifies one or more domains that can send LocalConnection calls to this LocalConnection object.

The allowInsecureDomain() method works just like the allowDomain() method, except that the allowInsecureDomain() method additionally permits SWF files from non-HTTPS origins to send LocalConnection calls to files from HTTPS origins. This difference is meaningful only if you call the allowInsecureDomain() method from a file that was loaded using HTTPS. You must call the allowInsecureDomain() method even if you are crossing a non-HTTPS/HTTPS boundary within the same domain; by default, LocalConnection calls are never permitted from non-HTTPS files to HTTPS files, even within the same domain.

Calling allowInsecureDomain() is not recommended, because it can compromise the security offered by HTTPS. When you load a file over HTTPS, you can be reasonably sure that the file will not be tampered with during delivery over the network. If you then permit a non-HTTPS file to make LocalConnection calls to the HTTPS file, you are accepting calls from a file that may in fact have been tampered with during delivery. This generally requires extra vigilance because you cannot trust the authenticity of LocalConnection calls arriving at your HTTPS file.

By default, files hosted using the HTTPS protocol can be accessed only by other files hosted using the HTTPS protocol. This implementation maintains the integrity provided by the HTTPS protocol.

Using this method to override the default behavior is not recommended, because it compromises HTTPS security. However, you might need to do so, for example, if you need to permit access to HTTPS SWF files published for Flash Player 9 or later from HTTP files SWF published for Flash Player 6 or earlier.

For more information related to security, see the Flash Player Developer Center Topic: Security.

Parameters

... domains — One or more strings that name the domains from which you want to allow LocalConnection calls. There are two special cases for this parameter:
  • You can specify the wildcard character "*" to allow calls from all domains. Specifying "*" does not include local hosts.
  • You can specify the string "localhost" to allow calls to this SWF file from SWF files that are installed locally. Flash Player 8 introduced security restrictions on local SWF files. A SWF file that is allowed to access the Internet cannot also have access to the local file system. If you specify "localhost", any local SWF file can access this SWF file. Remember that you must also designate the calling SWF file as a local-with-networking SWF file at authoring time.


Throws
ArgumentError — All parameters specified must be non-null strings.

More examples

Related API Elements

close

()method 
public function close():void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Closes (disconnects) a LocalConnection object. Issue this command when you no longer want the object to accept commands — for example, when you want to issue a connect() command using the same connectionName parameter in another SWF file.


Throws
ArgumentError — The LocalConnection instance is not connected, so it cannot be closed.

Related API Elements

connect

()method 
public function connect(connectionName:String):void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Prepares a LocalConnection object to receive commands that are sent from a send() command (from the sending LocalConnection object). The object used with the connect() method is called the receiving LocalConnection object. The receiving and sending objects must be running on the same client computer.

To avoid a race condition, define the methods attached to the receiving LocalConnection object before calling this method, as shown in the LocalConnection class example.

By default, the connectionName argument is resolved into a value of "superdomain:connectionName", where superdomain is the superdomain of the file that contains the connect() command. For example, if the file that contains the receiving LocalConnection object is located at www.someDomain.com, connectionName resolves to "someDomain.com:connectionName". (If a file running in Flash Player is located on the client computer, the value assigned to superdomain is "localhost".)

In content running in the application security sandbox in Adobe AIR (content installed with the AIR application), the runtime uses the string app# followed by the application ID for the AIR application (defined in the application descriptor file) in place of the superdomain. For example a connectionName for an application with the application ID com.example.air.MyApp connectionName resolves to "app#com.example.air.MyApp:connectionName".

Also by default, Flash Player lets the receiving LocalConnection object accept commands only from sending LocalConnection objects whose connection name also resolves into a value of "superdomain:connectionName". In this way, Flash Player makes it simple for files that are located in the same domain to communicate with each other.

If you are implementing communication only between files in the same domain, specify a string for connectionName that does not begin with an underscore (_) and that does not specify a domain name (for example, "myDomain:connectionName"). Use the same string in the connect(connectionName) method.

If you are implementing communication between files in different domains, specifying a string for connectionName that begins with an underscore (_) makes the file with the receiving LocalConnection object more portable between domains. Here are the two possible cases:

  • If the string for connectionNamedoes not begin with an underscore (_), a prefix is added with the superdomain and a colon (for example, "myDomain:connectionName"). Although this ensures that your connection does not conflict with connections of the same name from other domains, any sending LocalConnection objects must specify this superdomain (for example, "myDomain:connectionName"). If the file with the receiving LocalConnection object is moved to another domain, the player changes the prefix to reflect the new superdomain (for example, "anotherDomain:connectionName"). All sending LocalConnection objects would have to be manually edited to point to the new superdomain.
  • If the string for connectionNamebegins with an underscore (for example, "_connectionName"), a prefix is not added to the string. This means that the receiving and sending LocalConnection objects use identical strings for connectionName. If the receiving object uses allowDomain() to specify that connections from any domain will be accepted, the file with the receiving LocalConnection object can be moved to another domain without altering any sending LocalConnection objects.

For more information, see the discussion in the class overview and the discussion of connectionName in send(), and also the allowDomain() and domain entries.

Note: Colons are used as special characters to separate the superdomain from the connectionName string. A string for connectionName that contains a colon is not valid.

When you use this method , consider the Flash Player security model. By default, a LocalConnection object is associated with the sandbox of the file that created it, and cross-domain calls to LocalConnection objects are not allowed unless you call the LocalConnection.allowDomain() method in the receiving file. You can prevent a file from using this method by setting the allowNetworking parameter of the the object and embed tags in the HTML page that contains the SWF content. However, in Adobe AIR, content in the application security sandbox (content installed with the AIR application) are not restricted by these security limitations.

For more information related to security, see the Flash Player Developer Center Topic: Security.

Parameters

connectionName:String — A string that corresponds to the connection name specified in the send() command that wants to communicate with the receiving LocalConnection object.


Throws
TypeError — The value passed to the connectionName parameter must be non-null.
 
ArgumentError — This error can occur for three reasons: 1) The string value passed to the connectionName parameter was null. Pass a non-null value. 2) The value passed to the connectionName parameter contained a colon (:). Colons are used as special characters to separate the superdomain from the connectionName string in the send() method, not the connect()method. 3) The LocalConnection instance is already connected.

More examples

Related API Elements

send

()method 
public function send(connectionName:String, methodName:String, ... arguments):void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Invokes the method named methodName on a connection that was opened with the connect(connectionName) method (in the receiving LocalConnection object). The object used with the send() method is called the sending LocalConnection object. The SWF files that contain the sending and receiving objects must be running on the same client computer.

There is a 40 kilobyte limit to the amount of data you can pass as parameters to this command. If send() throws an ArgumentError but your syntax is correct, try dividing the send() requests into multiple commands, each with less than 40K of data.

As discussed in the connect() entry, the current superdomain in added to connectionName by default. If you are implementing communication between different domains, you need to define connectionName in both the sending and receiving LocalConnection objects in such a way that the current superdomain is not added to connectionName. You can do this in one of the following two ways:

  • Use an underscore (_) at the beginning of connectionName in both the sending and receiving LocalConnection objects. In the file that contains the receiving object, use LocalConnection.allowDomain() to specify that connections from any domain will be accepted. This implementation lets you store your sending and receiving files in any domain.
  • Include the superdomain in connectionName in the sending LocalConnection object — for example, myDomain.com:myConnectionName. In the receiving object, use LocalConnection.allowDomain() to specify that connections from the specified superdomain will be accepted (in this case, myDomain.com) or that connections from any domain will be accepted.

Note: You cannot specify a superdomain in connectionName in the receiving LocalConnection object — you can do this in only the sending LocalConnection object.

When you use this method , consider the Flash Player security model. By default, a LocalConnection object is associated with the sandbox of the file that created it, and cross-domain calls to LocalConnection objects are not allowed unless you call the LocalConnection.allowDomain() method in the receiving file. For SWF content running in the browser, ou can prevent a file from using this method by setting the allowNetworking parameter of the the object and embed tags in the HTML page that contains the SWF content. However, in Adobe AIR, content in the application security sandbox (content installed with the AIR application) are not restricted by these security limitations.

For more information related to security, see the Flash Player Developer Center Topic: Security.

Parameters

connectionName:String — Corresponds to the connection name specified in the connect() command that wants to communicate with the sending LocalConnection object.
 
methodName:String — The name of the method to be invoked in the receiving LocalConnection object. The following method names cause the command to fail: send, connect, close, allowDomain, allowInsecureDomain, client, and domain.
 
... arguments — Additional optional parameters to be passed to the specified method.


Events
securityError:SecurityErrorEventLocalConnection.send() attempted to communicate with a SWF file from a security sandbox to which the calling code does not have access. You can work around this in the receiver's implementation of LocalConnection.allowDomain().
 
status:StatusEvent — If the value of the level property is "status", the call was successful; if the value is "error", the call failed. The call can fail if the receiving SWF file refuses the connection.

Throws
TypeError — The value of either connectionName or methodName is null. Pass non-null values for these parameters.
 
ArgumentError — This error can occur for one of the following reasons: 1) The value of either connectionName or methodName is an empty string. Pass valid strings for these parameters. 2) The method specified in methodName is restricted. 3) The serialized message that is being sent is too large (larger than 40K).

More examples

Related API Elements

Event Detail

asyncError

Event
Event Object Type: flash.events.AsyncErrorEvent
property AsyncErrorEvent.type = flash.events.AsyncErrorEvent.ASYNC_ERROR

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Dispatched when an exception is thrown asynchronously — that is, from native asynchronous code.

The AsyncErrorEvent.ASYNC_ERROR constant defines the value of the type property of an asyncError event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object dispatching the event.
errorThe error that triggered the event.

securityError

Event  
Event Object Type: flash.events.SecurityErrorEvent
property SecurityErrorEvent.type = flash.events.SecurityErrorEvent.SECURITY_ERROR

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Dispatched if a call to LocalConnection.send() attempts to send data to a different security sandbox.

The SecurityErrorEvent.SECURITY_ERROR constant defines the value of the type property of a securityError event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe network object reporting the security error.
textText to be displayed as an error message.

Related API Elements

status

Event  
Event Object Type: flash.events.StatusEvent
property StatusEvent.type = flash.events.StatusEvent.STATUS

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Dispatched when a LocalConnection object reports its status. If LocalConnection.send() is successful, the value of the status event object's level property is "status"; if the call fails, the level property is "error". If the receiving file refuses the connection, the call can fail without notification to the sending file.

Defines the value of the type property of a status event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
codeA description of the object's status.
currentTargetThe object that is actively processing the Event object with an event listener.
levelThe category of the message, such as "status", "warning" or "error".
targetThe object reporting its status.

Related API Elements

LocalConnectionSenderExample.as

This example consists of two ActionScript classes which should be compiled into two separate SWF files:

In the LocalConnectionSenderExample SWF file, a LocalConnection instance is created, and when the button is pressed the call() method is used to call the method named lcHandler in the SWF file with the connection name "myConnection," passing the contents of the TextField as a parameter.

In the LocalConnectionReceiverExample SWF file, a LocalConnection instance is created and the connect() method is called to designate this SWF file as the recipient of messages that are addressed to the connection named "myConnection." In addition, this class includes a public method named lcHandler(); this method is the one that is called by the LocalConnectionSenderExample SWF file. When it's called, the text that is passed in as a parameter is appended to the TextField on the Stage.

Note: To test the example, both SWF files must be loaded on the same computer simultaneously.

// Code in LocalConnectionSenderExample.as
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.net.LocalConnection;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.events.StatusEvent;
    import flash.text.TextFieldAutoSize;

    public class LocalConnectionSenderExample extends Sprite {
        private var conn:LocalConnection;
        
        // UI elements
        private var messageLabel:TextField;
        private var message:TextField;
        private var sendBtn:Sprite;
        
        public function LocalConnectionSenderExample() {
            buildUI();
            sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
            conn = new LocalConnection();
            conn.addEventListener(StatusEvent.STATUS, onStatus);
        }
        
        private function sendMessage(event:MouseEvent):void {
            conn.send("myConnection", "lcHandler", message.text);
        }
        
        private function onStatus(event:StatusEvent):void {
            switch (event.level) {
                case "status":
                    trace("LocalConnection.send() succeeded");
                    break;
                case "error":
                    trace("LocalConnection.send() failed");
                    break;
            }
        }
        
        private function buildUI():void {
            const hPadding:uint = 5;
            // messageLabel
            messageLabel = new TextField();
            messageLabel.x = 10;
            messageLabel.y = 10;
            messageLabel.text = "Text to send:";
            messageLabel.autoSize = TextFieldAutoSize.LEFT;
            addChild(messageLabel);
            
            // message
            message = new TextField();
            message.x = messageLabel.x + messageLabel.width + hPadding;
            message.y = 10;
            message.width = 120;
            message.height = 20;
            message.background = true;
            message.border = true;
            message.type = TextFieldType.INPUT;
            addChild(message);
            
            // sendBtn
            sendBtn = new Sprite();
            sendBtn.x = message.x + message.width + hPadding;
            sendBtn.y = 10;
            var sendLbl:TextField = new TextField();
            sendLbl.x = 1 + hPadding;
            sendLbl.y = 1;
            sendLbl.selectable = false;
            sendLbl.autoSize = TextFieldAutoSize.LEFT;
            sendLbl.text = "Send";
            sendBtn.addChild(sendLbl);
            sendBtn.graphics.lineStyle(1);
            sendBtn.graphics.beginFill(0xcccccc);
            sendBtn.graphics.drawRoundRect(0, 0, (sendLbl.width + 2 + hPadding + hPadding), (sendLbl.height + 2), 5, 5);
            sendBtn.graphics.endFill();
            addChild(sendBtn);
        }
    }
}
LocalConnectionReceiverExample.as

// Code in LocalConnectionReceiverExample.as
package {
    import flash.display.Sprite;
    import flash.net.LocalConnection;
    import flash.text.TextField;

    public class LocalConnectionReceiverExample extends Sprite {
        private var conn:LocalConnection;
        private var output:TextField;
        
        public function LocalConnectionReceiverExample()     {
            buildUI();
            
            conn = new LocalConnection();
            conn.client = this;
            try {
                conn.connect("myConnection");
            } catch (error:ArgumentError) {
                trace("Can't connect...the connection name is already being used by another SWF");
            }
        }
        
        public function lcHandler(msg:String):void {
            output.appendText(msg + "\n");
        }
        
        private function buildUI():void {
            output = new TextField();
            output.background = true;
            output.border = true;
            output.wordWrap = true;
            addChild(output);
        }
    }
}