Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an embedded Flash object access the DOM of its parent document?

I'm just curious if it's possible that Flash objects can access the DOM of the document that has embedded it.

like image 732
devviedev Avatar asked Mar 18 '10 20:03

devviedev


2 Answers

Yes, through the ExternalInterface class.

You can make calls to Javascript from within the Flash movie and get back any public information about the page that your heart desires.

Addendum

Looking at this a year and a half later, i decided to add some examples:

Say you have a JS function on your client page like this:

function foo(bar,type) {
  // do something with bar and type
}

You call it from Flash (using AS3) like so:

ExternalInterface.call(foo, bar, type);

Note that the function name is the first object and the arguments are listed sequentially thereafter.

To expose a method of the Flash movie to outside Javascript, you would do this in your Flash or Flex (again, AS3):

application1_applicationCompleteHandler(event:Event) {
  // the app has finished loading, so do whatever we
  // have to do on load, plus add that callback
  ExternalInterface.addCallback(foo, bar);
}

public function bar(arg1, arg2) : void {
  // do something with arg1 and arg2
}

In the Javascript on the page you invoke it like this (where myMovie is the ID of the SWF):

myMovie.foo(anArg, anotherArg);

In the addCallback method, the first argument is the external name of the function, and the second argument is the closure that will get called.

like image 166
Robusto Avatar answered Sep 28 '22 00:09

Robusto


Yes.

An example: http://livedocs.adobe.com/flex/3/html/help.html?content=ProgrammingHTMLAndJavaScript_07.html

like image 40
Yuval Adam Avatar answered Sep 28 '22 01:09

Yuval Adam