0

I have a flash swf object that gets embedded in the facebook news feed. I can't control anything other than the swf file itself. Its hosted on our server and I need to be able to read a cookie our main website sets.

Everything I can find talks about using external javascript to read and set the cookie, but I want to do it from inside of flash itself.

The Digital Ninja
  • 1,090
  • 6
  • 22
  • 36

2 Answers2

2

You can actually do a lot more with ExternalInterface than people realize. Define your function in AS3, and then pass it to ExternalInterface as a parameter in an ExternalInterface.call. I built a simple AS3 project with this as a property of the main class.

private var myTestJS:String = "function myTest(parameter){alert(parameter);return parameter;}";

and this in the constructor

var mycookievalue:String = ExternalInterface.call(myTestJS, "Yay for ExternalInterface");

Build a quick project, debug that and you'll see that both the alert gets called as well as mycookievalue gets set correctly. Now, you just need to replace my test function with your js code to pick up the cookie.

Robert Smith
  • 385
  • 4
  • 15
  • Just noticed there's some code shared on a different comment that may make this even easier for you. http://stackoverflow.com/questions/689215/is-it-possible-to-value-store-cookies-in-flash-or-flex?rq=1 – Robert Smith Jun 27 '12 at 12:58
0

Flash Player can't access browser cookies. The ExternalInterface approach is a trick to get JavaScript to do it for you.

Flash Player can access Shared Objects, which are like the Flash Player's version of cookies; but generally Flash and the browser do not share cookies.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Can I call an external interface to javascript on a different page inside an iframe in facebook? such as beta.site.com in an iframe calls js.site.com/StupidFlash.js and have that return it? – The Digital Ninja Jun 26 '12 at 17:22
  • I believe ExternalInterface will only work for the page which contains the SWF; and for that to work both the page and the SWF must be served off the same domain. ( Otherwise that is the very definition of cross site scripting; which can be used for nefarious purposes). I thought there was an attribute you could in the way that the Flash app was embedded in the enclosing page to allow for this "Cross domain" access; but I don't know it off the top of my head. – JeffryHouser Jun 26 '12 at 17:33