Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Flash button hide/show a DIV-Layer on a html page?

Question posted by: elamberdor (Member) on August 23rd, 2007 01:06 AM
Hi All!
Trying to get a drop down hide/show div on a html page triggered by a button in flash.
(Intro: Very very Little experience in dynamic flash)

setup: html page, flash map on page, button on flash opens info underneath map in a separate div. div that has hide/show content is called "operator"

I found this code, but i'm not sure it's what I need, and it's not working...

Flash file>button on stage>script:
Code: ( text )
  1. on (release) {
  2. import flash.external.ExternalInterface;
  3. ExternalInterface.call("hideDiv", "operator");
  4. }


And the code in the html file:
Code: ( text )
  1. <html>
  2. <head>
  3. <title>page title</title>
  4. <script type="text/javascript">
  5. function hideDiv(id)
  6. {
  7.    document.getElementById(id).style.display = 'none';
  8. }
  9. </script>
  10. </head>
  11. <body>
  12. <div id="operator">
  13. </div>
  14. </body>
  15. </html>


Does anyone have a better (working) way of getting a flash button to talk to the html page to *togggle* a hidden div?

Any ideas would be muchly appreciated!
Thankyou so much in advance!
=)
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
elamberdor's Avatar
elamberdor
Member
38 Posts
August 23rd, 2007
06:45 AM
#2

Re: Flash button hide/show a DIV-Layer on a html page?
I eventually got it to work! (Flash8, I.E 7)
Here's the answer explained for anyone else that needs it!

But I changed it a little to make it toggle......

What i've done is made the "operator" div hidden on page load with a css class attached to the div to start with:

in css file:
Code: ( text )
  1. .clearfix:after {
  2. content: ".";
  3. display: block;
  4. height: 0;
  5. clear: both;
  6. visibility: hidden;
  7. }


then in flash:
ive got a button on the stage with:

Code: ( text )
  1. on (press) {
  2. import flash.external.ExternalInterface;
  3. ExternalInterface.call("toggleLayer", "operator");
  4. }


(i'm still researching AS3 regarding on (release) button and still getting my head around the new script - its quite hard to grasp!)

then in the html file, ive got a link to the css file and the javascript in the header telling it to toggle:
Code: ( text )
  1. <head>
  2. <link href="../css/SVW_css_test_1.css" rel="stylesheet" title="medium" type="text/css">
  3. <script type="text/javascript">
  4. function toggleLayer( whichLayer )
  5. {
  6. var elem, vis;
  7. if( document.getElementById ) // this is the way the standards work
  8. elem = document.getElementById( whichLayer );
  9. else if( document.all ) // this is the way old msie versions work
  10. elem = document.all[whichLayer];
  11. else if( document.layers ) // this is the way nn4 works
  12. elem = document.layers[whichLayer];
  13. vis = elem.style;
  14. // if the style.display value is blank we try to figure it out here
  15. if(vis.display==''&&elem.offsetWidth!=undefined&&e lem.offsetHeight!=undefined)
  16. vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block ':'none';
  17. vis.display = (vis.display==''||vis.display=='block')?'none':'bl   ock';
  18. }
  19. //-->
  20. </script>
  21.  
  22. </head>


then i've got the div in the body with the class of clearfix to make it invisible on page load:
Code: ( text )
  1. <div id="operator" class="clearfix">


Thanks!!
=)

Reply
crabpot8's Avatar
crabpot8
Member
39 Posts
August 23rd, 2007
11:25 PM
#3

Re: Flash button hide/show a DIV-Layer on a html page?
out of curiosity, do you know what this line does?

import flash.external.ExternalInterface;

that is a reallly useful thing to know!

Reply
elamberdor's Avatar
elamberdor
Member
38 Posts
August 23rd, 2007
11:37 PM
#4

Re: Flash button hide/show a DIV-Layer on a html page?
Hi there!

Well ~ As far as I know (which with Dynamic flash is VERY limited)

You can call in images and swf's using the Load script into flash, but to do the opposite and use things in flash to affect things outside the flash file, you use the
Code: ( text )
  1. ExternalInterface.call() function

it is used to call things like Javascript functions on the flash's HTML page. Apparently it is a more advanced version of this:
Code: ( text )
  1. navigateToURL(new URLRequest("javascript:hideDiv('my_div_id');"));

Reply
xNephilimx's Avatar
xNephilimx
Expert
162 Posts
August 24th, 2007
12:52 AM
#5

Re: Flash button hide/show a DIV-Layer on a html page?
Hi, there.
Not quite, the ExternalInterface class lets you communicate with javascript back and forth.
Here is a pretty good explanation http://www.thescripts.com/forum/thread694359.html

Kind regards,
The_Nephilim

Quote:
Originally Posted by elamberdor
Hi there!

Well ~ As far as I know (which with Dynamic flash is VERY limited)

You can call in images and swf's using the Load script into flash, but to do the opposite and use things in flash to affect things outside the flash file, you use the
Code: ( text )
  1. ExternalInterface.call() function

it is used to call things like Javascript functions on the flash's HTML page. Apparently it is a more advanced version of this:
Code: ( text )
  1. navigateToURL(new URLRequest("javascript:hideDiv('my_div_id');"));

Reply
elamberdor's Avatar
elamberdor
Member
38 Posts
August 27th, 2007
02:06 AM
#6

Re: Flash button hide/show a DIV-Layer on a html page?
sounds good, i'll have a read!

Reply
miao's Avatar
miao
Newbie
1 Posts
July 7th, 2008
08:54 PM
#7

Re: Flash button hide/show a DIV-Layer on a html page?
hi! thank you for these instructions. I followed them exactly but couldn't get it to work. (the button inside the div is already visible when the page is opened.)
I have been searching the web for days now cause I'm not very experienced in java and actionscript.
please help!

Reply
Reply
Not the answer you were looking for? Post your question . . .
183,939 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Flash / Actionscript Forum Contributors