Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling a javascript function from flash

Posted on 2010-11-10
17
Medium Priority
?
454 Views
Last Modified: 2012-05-10
Bellow is some JavaScript that I'm using for some drop-down menus.
http://www.leigeber.com/2008/11/drop-down-menu/

every thing is working as desired with the static version.

I would like to be able to call the onmouseover and onmouseout functions from Flash or other links on the page.

I'm not that familiar with JavaScript but it looks to me like there are new functions being created for each list element at run-time. How would i create over and out functions for the specific menu elements that i could call from anywhere in the page?

<script type="JavaScript">
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();
</script>

     <div id="staticWrapper" style=" background-image: url(images/menu-bar-bg.png); background-repeat:repeat-x; height:147px; width:100%; z-index:-2; top:0px; position:absolute;">
    <div id="logo" style="width:953px; margin-left:auto; margin-right:auto; z-index:-1;"> <img src="images/static-logo-new.png" border="0" alt="" title="Syndicated Solar" style="margin-left:35px; margin-top:3px"/>
    </div>
     	<div id="staticMenu" style="width:953px; margin-left:auto; margin-right:auto; z-index:-1;">
        <ul class="menu" id="menu">
	<li><a href="#" class="homeLink">HOME PAGE</a>
		<ul>
			<li><a href="#">Navigation Item 1</a></li>
			<li>
				<a href="#" class="sub">Navigation Item 2</a>
				<ul>
					<li class="topline"><a href="#">Navigation Item 1 sub</a></li>
					<li><a href="#">Navigation Item 2 sub</a></li>
					<li><a href="#">Navigation Item 3 sub</a></li>
					<li><a href="#">Navigation Item 4 sub</a></li>
					<li><a href="#">Navigation Item 5 sub</a></li>
				</ul>
			</li>
			<li>
				<a href="#" class="sub">Navigation Item 3</a>
				<ul>
					<li class="topline"><a href="#">Navigation Item 1</a></li>
					<li><a href="#">Navigation Item 2</a></li>
					<li>
						<a href="#" class="sub">Navigation Item 3</a>
						<ul>
							<li class="topline"><a href="#">Navigation Item 1</a></li>
							<li><a href="#">Navigation Item 2</a></li>
							<li><a href="#">Navigation Item 3</a></li>
							<li><a href="#">Navigation Item 4</a></li>
							<li><a href="#">Navigation Item 5</a></li>
							<li><a href="#">Navigation Item 6</a></li>
						</ul>
					</li>
					<li><a href="#">Navigation Item 4</a></li>
				</ul>
			</li>
			<li><a href="#">Navigation Item 4</a></li>
			<li><a href="#">Navigation Item 5</a></li>
		</ul>
	</li>
       </ul>
  </div>
</div>

<style type="text/css">
	
ul.menu {list-style:none; margin:0; float:left; padding-left:10px; padding-top:14px;}
ul.menu * {margin:0; padding:0}
ul.menu a {display:block; color:#FFF; text-decoration:none}
ul.menu li {position:relative; float:left; margin-right:2px;}
ul.menu ul {position:absolute; top:26px; left:0; background:#d1d1d1; display:none; opacity:0; list-style:none; margin-top:9px; }
ul.menu ul li {position:relative; border:1px solid #828282;; border-top:none; width:148px; margin:0}
ul.menu ul li a {display:block; padding:3px 7px 5px; background-color:#202020; color:#bababa;}
ul.menu ul li a:hover {background-color:#CE470C; color:#222; }
ul.menu ul ul {left:148px; top:-1px}
ul.menu .menulink {border:0px; padding:5px 7px 7px; font-weight:bold; }
ul.menu .menulink:hover, ul.menu .menuhover {}
ul.menu .sub {background:#202020 url(images/arrow.gif) 136px 8px no-repeat; }
ul.menu .topline {border-top:1px solid #828282; }

 ul.menu .homeLink:hover {background:url(../../images/home.png) no-repeat; color:white; width:102px;}
 ul.menu .homeLink {background:none; width:102px; height:24px; text-align:center; padding-top:5px;}
 
 ul.menu .productsLink:hover {background:url(../../images/products.png) no-repeat; color:white; width:169px;}
 ul.menu .productsLink {background:none; width:169px; height:24px; text-align:center; padding-top:5px;}
 
 ul.menu .customersLink:hover {background:url(../../images/customers.png) no-repeat; color:white; width:131px;}
 ul.menu .customersLink {background:none; width:131px; height:24px; text-align:center; padding-top:5px;}
</style>

Open in new window


Thanks in advance!
0
Comment
Question by:Cybervanes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
17 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34109748
1. http://scriptplayground.com/tutorials/as/Call-Javascript-in-Flash/

2.
var js = "document.links[3].onmouseover()"; // mouse over the 4th link on the page
 runJS(js);
 


0
 
LVL 2

Author Comment

by:Cybervanes
ID: 34113486
so theoretically i should be able to call `document.links[3].onmouseover();` from an anchor tag as well right?

<a href="javascript:document.links[2].onmouseover();">click here</a>

this dose not work. error: ` document.links[2].onmouseover is not a function.`

any other ideas?
 
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34113977
better


<a href="#" onClick="document.links[2].onmouseover(); return false">click here</a>

assuming document.links[2] HAS a mouseover
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Cybervanes
ID: 34114058
No that didn't work either...

the above script seems to be attaching onmouseover functions to the `UL` tags. but i cant figure out how to call those function for the individual tags.

if you would like i cloud email you a link to our testing server.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34114099

<a href="#" onClick="document.getElementsByTagName('ul')[2].onmouseover(); return false">click here</a>

my email is in my profile
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 34114150
that didn't work either...

emailed link.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34114566
Ah, ok I will look
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34114647
Sorry. Not a clue.
0
 
LVL 6

Expert Comment

by:stilliard
ID: 34115494
have you tried the actionscript class ExternalInterface ? you can use it to call javascript from the page its called from. O think this could be used for the purpose you need.
more info and a similar issue here:
http://bytes.com/topic/flash/answers/694359-how-do-i-access-flash-function-using-javascript
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 34115533
Yes I'm aware of how to call JavaScript functions from flash. getURL("JavaScript:frunctionName()");

my question is based on the above script... what function would i call to activate the on-rollover functionality of each menu item.

thanks,
0
 
LVL 6

Expert Comment

by:stilliard
ID: 34115822
well if you have jQuery on the page you could run $('.menulink:first').mouseover();
working on a raw js version atm
0
 
LVL 6

Expert Comment

by:stilliard
ID: 34115974
this javascript should work.

document.getElementById('menu').getElementsByTagName('ul')[0].parentNode.onmouseover();
0
 
LVL 6

Accepted Solution

by:
stilliard earned 2000 total points
ID: 34116016
little explanation incase needed:

document.getElementById('menu').getElementsByTagName('ul')[0].parentNode.onmouseover();

get the menu element, then get all its child ul elements, select the first (index 0) and then get its parent element, then call the mouseover event on it.
So "document.getElementById('menu').getElementsByTagName('ul')" selects all the sub menus, then all thats needed was to select the one you want, in my case i referenced the first, get the parent node and trigger the event.
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 34116043
Very Nice stilliard... You need a promotion! testing and working good!
0
 
LVL 2

Author Closing Comment

by:Cybervanes
ID: 34116048
great job! Thank You!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34116416
So I was really close
0
 
LVL 2

Author Comment

by:Cybervanes
ID: 34117639
thank you both for your help!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question