Checking if my popup has opened

I’ve got a bit of code that opens a popup, then tries to send info to it using localConnection. It’s not working, is it because it’s sending the connection too early? How can I make it check that the window is open before I send it?


//Open Popup
getURL  ("javascript:var myWin; if(!myWin || myWin.closed){myWin = window.open('" +  winURL  +  "','"  +  winName  +  "','"  +  "width="  +  winWidth  +  ",height="  +  winHeight  +  ",toolbar="  +  winToolbar  +  ",location="  +  winLocation  +  ",directories="  +  winDirectories  +  ",status="  +  winStatus  +  ",menubar="  +  winMenuBar  +  ",scrollbars="  +  winScrollbars  +  ",resizable="  +  winResizable  +  ",top='+((screen.height/2)-("  +  h/2  +  "))+',left='+((screen.width/2)-("  +  w/2  +  "))+'"  +  "')}else{myWin.focus();};void(0);");

//Send the picture info
sendPictureInfo = new LocalConnection();
sendPictureInfo.send("pictureInfoConnection", "pictureInfoFunction", "Ben rules ok!");