04
Nov
2008

reading a div from dom in actionscript 3 (as3) – flash

in order to read a div from your html document,
first you to add the ‘allowScriptAccess’ in the flash injection (like swfobject) to sameDomain
some thing like : so.addParam(‘allowScriptAccess’,'sameDomain’);

(will try to write more about using swfobject soon..)

then in the flash you include the ExternalInterface class:
include flash.external.ExternalInterface;

then you can use something like :
var myDivContent = ExternalInterface.call(‘function(){ return document.GetElementById(‘flashDiv’);}’);

and in the html file :

bla bla bla

you can add style=’display:none’ in you want this div to be hidden.

it’s good for the page seo as the text will be html text, but you show it thru the flash …

http://www.adylevy.com/wp-content/plugins/sociofluid/images/digg_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/stumbleupon_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/delicious_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/furl_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/technorati_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/google_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/myspace_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/facebook_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/yahoobuzz_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/twitter_32.png http://www.adylevy.com/wp-content/plugins/sociofluid/images/meneame_32.png
Posted in as3

4 comments »

  1. laxroabslesCleds said,
    December 31, 2008 @ 4:26 am

    well, hi admin ady people nice forum indeed. how’s life? hope it’s introduce branch ;)

  2. Sci-Fi Si said,
    February 17, 2009 @ 9:16 pm

    Nice one Ady, this is just the sort of thing I’m working on at the moment.

    What I would like to achieve is to be able to read the ‘entire’ content of the HTML page from AS3.

    This way if Flash is installed the entire HTML page could be rendered in Flash and look great.

    If Flash isn’t installed the HTML/JavaScript would be rendered by the browser.

    Do you know if this can be done?

    Thanks for you article.
    Si

  3. admin said,
    February 20, 2009 @ 10:16 pm

    Hi,
    i’ve seen some html classes for flash that can render an html page, i do remember it was open source, and not completed. can’t find it anywhere now :) sorry ..

    donno what excatly you wan’t to do, but you can use a hidden div with some text / xml / images or whatever and load it with the flash.

    check out:
    http://rollersurfer.com/products-gear/switch

    the content is inside the page (from php) and the flash read’s it with this method.

    the only problem i see in what you want is that when the flash is “injected” to some div, it overides that div’s content.

Leave a Comment