Tag: byteArray

LocalConnection – AIR -> Flex (and back if you want)

LocalConnection – AIR -> Flex (and back if you want)

One of the long standing flex projects I’ve been working on is a tool for showing of various funds and fund videos with related PDF’s and graphs etc.  This is updated relatively frequently and due to various restrictions it’s not as straight forward to test updates as the client would like.

So what would be a good way to test a live flex app (which is static) that loads dynamic data. Well the idea was to create an AIR application that would be a visual editor for the data that would then send that data using LocalConnection, this would update the model in the live flex app and the new data would be displayed so that it could be checked.  All of this would be local to the clients machine as by using the localConnection you’re only changing the local data model and not the data on the server.

Sounds very straight forward, but getting it just right took a little while.

Here’s the basic on how. (open demo windows, run both apps and right click for source to get more detail)

AIR application

Flex application

1)    Create an AIR app that sets up a localconnection

2)    Create a byteArray of whatever you wish to send (I’m sending just text, but there is no reason why you couldn’t say send an image or similar)

3)    Split byteArray into chunks of under 40K and then send them across using localConnection

4)    At the same time create a flex application with a localConnection

5)    Let it allow the domain your message is coming from (start with * for testing if not sure, just make sure you don’t leave * in for any live version)

6)    Create a handler function that matches the name of localConnection send parameter that you set up in the AIR app

7)    Join the 40K chucks of data if necessary then do what you like with them.

That’s it, message received over and out :).  check out the source code for more details.

[ad name=”ad-1″]