# Javascript question

**URL:** <https://forum.kirupa.com/t/javascript-question/2862>\
**Category:** web dev\
**Created:** [March 20, 2002, 5:05pm UTC](https://forum.kirupa.com/t/javascript-question/2862 "2002-03-20T17:05:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2002, 5:05pm UTC](https://forum.kirupa.com/t/javascript-question/2862/1 "2002-03-20T17:05:59Z")

</div>

Is it possible to put javascript directly into flash??? And if so, how?\rThanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2002, 9:44pm UTC](https://forum.kirupa.com/t/javascript-question/2862/2 "2002-03-20T21:44:37Z")

</div>

What is it that you really want to do? What I mean is, what would be the point of putting it in there?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2002, 11:38pm UTC](https://forum.kirupa.com/t/javascript-question/2862/3 "2002-03-20T23:38:34Z")

</div>

this might clear it up…\rno, you can not put javascript in your swf’s.\rbut you can call javascript functions (and pass variables to them) from a swf. so, if you want to open a new window you can’t just put getURL(“javascript:new.window”,"\_blank"), but you could write a javascript function that opens a new window and call that function like this: getURL (“javascript:functionNameHere(parametersHere)”,"\_blank");\rif you are passing dynamic parameters from the swf:\rgetURL(“javascript:functionNameHere(”+parametersHere+")","\_blank");\rhope that helps!\rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2002, 6:31pm UTC](https://forum.kirupa.com/t/javascript-question/2862/4 "2002-03-21T18:31:08Z")

</div>

I am wondering about the exact same thing as John who posted this topic.\r\rYou say you can call javascript functions from your .swf.\rBut where do you write this Javascript function for starters?\r\r//m3rcc

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2002, 8:04pm UTC](https://forum.kirupa.com/t/javascript-question/2862/5 "2002-03-21T20:04:59Z")

</div>

you write it in your html, just like any other javascript function.\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 12:01am UTC](https://forum.kirupa.com/t/javascript-question/2862/6 "2002-03-22T00:01:59Z")

</div>

Sinfiniti probably know this 🙂 \r\rI have the function:\r—\rfunction openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { [//v3.0](https://v3.0)\r if(window.screen)if(isCenter)if(isCenter==“true”){\r var myLeft = (screen.width-myWidth)/2;\r var myTop = (screen.height-myHeight)/2;\r features+=(features!=’’)?’,’:’’;\r features+=’,left=’+myLeft+’,top=’+myTop;\r }\r window.open(theURL,winName,features+((features!=’’)?’,’:’’)+‘width=’+myWidth+’,height=’+myHeight)\r \r}\r—\r\rWhat do I write in the:\ron (release)\r{\rgetURL(" ??? ")\r}\r\rI’ve tried alot on this, though it won’t work :/\rHelp is appreciated\r\r//m3rcc

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 12:41am UTC](https://forum.kirupa.com/t/javascript-question/2862/7 "2002-03-22T00:41:32Z")

</div>

Put your code in an html doc, save it in the same directory as your .swf, and then…\r\r

```auto
 on (release) {\r\r getURL(whateveryoucalledyourHTMLdoc)\r\r}\r\r

```

\rDid I misunderstand? Flash would then load the HTML and execute the code contained within the page.\r\rCheers!\r-Niann

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 2:43am UTC](https://forum.kirupa.com/t/javascript-question/2862/8 "2002-03-22T02:43:13Z")

</div>

you can call that function and pass parameters like this:\rgetURL(“javascript\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=”:o"\> penBrWindow("+theURL+","+winName+","+features+","+myWidth+","+myHeight+","+isCenter+")","\_self");\rplay around with the ‘\_self’, ‘\_blank’, etc. to see which one works for you.\rthat should do it!\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 9:20am UTC](https://forum.kirupa.com/t/javascript-question/2862/9 "2002-03-22T09:20:28Z")

</div>

hmm… is it just me… or ☹ \r\rIn the index.html where I have embedded my .swf I have this javascript function in the HEAD tag:\r—\rfunction openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { [//v3.0](https://v3.0)\r if(window.screen)if(isCenter)if(isCenter==“true”){\r var myLeft = (screen.width-myWidth)/2;\r var myTop = (screen.height-myHeight)/2;\r features+=(features!=’’)?’,’:’’;\r features+=’,left=’+myLeft+’,top=’+myTop;\r }\r window.open(theURL,winName,features+((features!=’’)?’,’:’’)+‘width=’+myWidth+’,height=’+myHeight)\r—\r(the function is within it’s requierd script language=“JavaScript” , but I couldn’t write HTML for it on this forum) The script works, I have tried it on a HTML page before.\r\rAnd on a button in my Flash i have this action:\r—\ron (press) \r{\rgetURL (“javascript: openBrWindow(”+page.html+","+PageV.1.0+","+status=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0+","+600+","+400+","+true+")","\_blank");\r}\r—\rAnd it doesn’t work? :/\rI’m going nuts over this\r\r//m3rcc pulling his hair\r\r\r

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 11:08am UTC](https://forum.kirupa.com/t/javascript-question/2862/10 "2002-03-22T11:08:38Z")

</div>

if you paste that getURL line into flash you will notice that ‘page.html’ is a variable, and you might not have intended this. it’s looking for the variable ‘html’ in the clip (or object) named ‘page’. ‘PageV.1.0’ will not work either - the syntax will not work with flash because a variable/object can not have a number as it’s name.\rhere is what i think will work…\rgetURL (“javascript\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=”:o"\> penBrWindow(“page.html”,“PageV.1.0”,“status=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0”,600,400,“true”)","\_blank");\r\ri’m not entirely sure, but try it and let me know. basically that line does not pass any variables, just values. all values except the ‘600’ and ‘400’ are sent as strings.\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 4:59pm UTC](https://forum.kirupa.com/t/javascript-question/2862/11 "2002-03-22T16:59:59Z")

</div>

It didn’t work.\rIt just opened another HTML page and in the adress it said:\rjavascript\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=":o"\> penBrWindow(“hej.html”,“sidfan”,“status=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0”,600,400,“true”)\r\rAnd nothing could be seen on the page.\r\r//m3rcc

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 5:07pm UTC](https://forum.kirupa.com/t/javascript-question/2862/12 "2002-03-22T17:07:45Z")

</div>

is that when you’re testing it from flash, or from the html that contains the swf?\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 5:18pm UTC](https://forum.kirupa.com/t/javascript-question/2862/13 "2002-03-22T17:18:28Z")

</div>

ok, i did a test. try removing the ‘location=0’ in the window parameters.\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 22, 2002, 6:47pm UTC](https://forum.kirupa.com/t/javascript-question/2862/14 "2002-03-22T18:47:35Z")

</div>

Same thing happend again, a new HTML page opened with all the parameters in the address field, and nothing could be seen on the page itself.\r\rI must do something wrong, other elements I might have forgotten? Nothing special in the HTML file i want to open? … must be something :/\r\r//m3rcc

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 23, 2002, 2:10am UTC](https://forum.kirupa.com/t/javascript-question/2862/15 "2002-03-23T02:10:36Z")

</div>

do you get the error in the browser, or are you testing the movie in flash when you get the error?\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 23, 2002, 3:55pm UTC](https://forum.kirupa.com/t/javascript-question/2862/16 "2002-03-23T15:55:30Z")

</div>

I don’t get an error, When I press the button(I have tested clikcing from the .swf, from flash, from the HTML page with the .swf) a new HTML page opens with Nothing! on it. And in the address field it says exactly what I wrote in the “getURL”\r\rso… in my flash:\ron (release) \r{\rgetURL (“javascript\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=”:o"\> penBrWindow(“hej.html”,“sidfan”,“status=0,toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0”,600,400,“true”)","\_blank");\r}\r\rand in the adress field of the HTML page that opened when I clicked the button with the above code:\rjavascript\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=":o"\> penBrWindow(“hej.html”,“sidfan”,“status=0,toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0”,600,400,“true”)\r\rMaybe I have the wrong function? It ain’t supposed to work?\rI really don’t know…\r\r//m3rcc

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 23, 2002, 4:40pm UTC](https://forum.kirupa.com/t/javascript-question/2862/17 "2002-03-23T16:40:25Z")

</div>

Maybe this helps:\r\r[www.escalix.com/freepage/…kirupa.txt](http://www.escalix.com/freepage/Seticus/kirupa.txt)\r
