erikvold
erikvold

Reputation: 16558

Can JavaScript post messages to Flash?

I'm wondering if JavaScript can post JSON messages to Flash? and if so can you please provide an example or a link to one?

Upvotes: 1

Views: 362

Answers (2)

sberry
sberry

Reputation: 132138

Use ExternalInterface class to add callback methods that Javascript can call.

for example:

import flash.external.ExternalInterface;
ExternalInterface.addCallback("callbackName", doMyCallback);

function doMyCallback(someParam:Strimg):void {
    // use the AS3CoreLib JSON decoder like mentioned by @ludesign to decode the JSON string.
}

Then in your javascript, you can call the callbackName method on the flash object.

AS3CoreLib
ExternalInterface

Upvotes: 3

christophmccann
christophmccann

Reputation: 4211

I am pretty sure that you can use FlashVars for this. Been a long time since I have done it so I wouldnt be able to provide code but a quick google found a couple of links:

http://kb2.adobe.com/cps/164/tn_16417.html

http://www.permadi.com/tutorial/flashVars/index.html

Hope it helps.

Upvotes: -1

Related Questions