# Javascript Popup Function in Flash

**URL:** <https://forum.kirupa.com/t/javascript-popup-function-in-flash/42822>\
**Category:** flash\
**Created:** [February 13, 2004, 5:42am UTC](https://forum.kirupa.com/t/javascript-popup-function-in-flash/42822 "2004-02-13T05:42:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sintax321](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sintax321](https://forum.kirupa.com/u/sintax321)\
**Post date:** [February 13, 2004, 5:42am UTC](https://forum.kirupa.com/t/javascript-popup-function-in-flash/42822/1 "2004-02-13T05:42:02Z")

</div>

I"m trying to write a fucntion in flash to launch a javascript popup window but can’t seem to get the variables in right. Here is the code.

Button Code  
[AS]on (release) {  
\_root.popup(pic1,436,356);  
}[/AS]

Function in the first frame of the root  
[AS]function popup(number,picwidth,pichieght){  
getURL(“javascript:var mypopup = window.open(‘gallery/’+number+’.htm’,‘mySite’,‘toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=‘picwidth’,height=‘pichieght’,top=’+eval((screen.availHeight - ‘pichieght’) / 3)+’,left=’+eval((screen.availWidth - ‘picwidth’) / 2));mypopup.focus();”);  
}[/AS]

Any ideas?

---

<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:** [February 13, 2004, 9:46pm UTC](https://forum.kirupa.com/t/javascript-popup-function-in-flash/42822/2 "2004-02-13T21:46:48Z")

</div>

I have done something like this before. What I did was used JavaScript in the external page 🙂

Something like this…

```php
<SCRIPT LANGUAGE="JavaScript">
<!--
function resize(w, h){
 	var imgW = document.galleryImage.width;
	var imgH = document.galleryImage.height;	
	var centerWidth = (screen.width) ? (screen.width-imgW)/2 : 0;
	var centerHeight = (screen.height) ? (screen.height-imgH)/2 : 0;
	window.resizeTo(imgW, imgH);
	window.moveTo(centerWidth, centerHeight);
}
-->
</SCRIPT>

```

That would be your function, and it would be called onLoad of the page…

```php
<BODY ONLOAD="resize()">

```

And the image would have to be named “galleryImage” (unless changed in the script)…

```php
<IMG SRC="image.jpg" NAME="galleryImage">

```

Now of course if you have seperate pages for each image, that will be hassle to add into each page. And that is why for mine I put it in a PHP page, sent the URL to the image via a query string and pull that info in to load the image…

```php
<?
$img = $_GET["img"];
list($width, $height, $type, $attr) = getimagesize($img);
echo "<img src=\"$img\" NAME=\"galleryImage\" $attr>";
?>

```

Oh yeah, and note the javascript code repositions the window, I did this because when I used it the window was centered, and changing the window size after it is already centered makes it not so centered.
