help me with command to open specifically sized browser window in as 3

Revolution9
Revolution9 used Ask the Experts™
on
I'm working with an interactive U.S. map where, on clicking a state, the browser goes to a URL.  I want the URL to be specifically sized, and to open a separate window.  I'm attaching the code with my attempt, which only refreshes the browser window the map is on to the new URL.

Please help!  
}
		function mapClickListener(e:MouseEvent) {
      var urlList=[];
      urlList['ak']='http://www.gmlighting.net/repfinder_alaska.html,toolbar=yes,scrollbars=yes,resizable=yes,width=750,height=950'; // the URL of Alaska
      
      var id=e.target.name.substring(0,e.target.name.length-3);
      navigateToURL(new URLRequest(urlList[id]),'_self');
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
first and foremost using "_self" is not going to help.

change it to _blank

Author

Commented:
I did.  This line of code isn't working:

navigateToURL(new URLRequest(urlList[id]),'_blank,toolbar=yes,scrollbars=yes,resizable=yes,width=750,height=950');
Top Expert 2009

Commented:
if i do this...

var urlList = new Array("http://www.google.co.za");

function doClick(e:MouseEvent)
{
      navigateToURL(new URLRequest(urlList[0]),'_blank,toolbar=yes,scrollbars=yes,resizable=yes,width=750,height=950');
}

it works

so check that id and  urlList[id] evaluates correctly.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

The proven way will be to use Javascript function to open a new window from Flash with the parameters as you need.
In your flash container page (HTML page), create a javascript function and call that from flash using ExernalInterface

in JavaScript create following function:

function openWin(url)
{
      window.open(url,'mywindow', 'width=750, height=950, toolbar=yes, scrollbars=yes, resizable=yes');
}


and in you "mapClickListener" function call this by providing url:

ExternalInterface.call("openWin", "http://www.gmail.com");

Author

Commented:
Blue - Genie:

Can you write that into this .as script that came with the Flash Interactive Map.  If it works I'll award you the points.  Thanks so much.

package {
      import flash.display.MovieClip;
      import flash.events.MouseEvent;
      import flash.display.DisplayObject;
      import flash.net.navigateToURL;
      import flash.net.URLRequest;
      public class MapApplication extends flash.display.MovieClip {
            function MapApplication() {
                  initializeBorder();
                  initializeMap();
            }
            function initializeBorder() {
                  border.mouseEnabled=false;
                  border.mouseChildren=false;
            }
            function initializeMap() {
                  var a:Number;
                  var lands:Array=new Array();
                  for (a=0; a<map.numChildren; a++) {
                        lands.push(map.getChildAt(a));
                  }
                  for (a=0; a<lands.length; a++) {
                        mapNormal(lands[a]);
                        lands[a].buttonMode=true;
                        lands[a].addEventListener(MouseEvent.ROLL_OVER,mapRollOverListener);
                        lands[a].addEventListener(MouseEvent.ROLL_OUT,mapRollOutListener);
                        lands[a].addEventListener(MouseEvent.CLICK,mapClickListener);
                  }
            }
            function mapRollOverListener(e:MouseEvent) {
                  mapActive(DisplayObject(e.target));
            }
            function mapRollOutListener(e:MouseEvent) {
                  mapNormal(DisplayObject(e.target));
            }
            function mapClickListener(e:MouseEvent) {
                  var urlRequest=new URLRequest('http://www.flashimap.com/sample-link.php?location='+e.target.name.substring(0,e.target.name.length-3));
                  navigateToURL(urlRequest,'_self');
            }
            function mapNormal(o:DisplayObject) {
                  fillMap(o,'normal');
            }
            function mapActive(o:DisplayObject) {
                  fillMap(o,'active');
            }
            function fillMap(o:DisplayObject, type:String) {
                  var fill:DisplayObject;
                  var ratio:Number;
                  var widthRatio:Number;
                  var heightRatio:Number;
                  if (type=='normal') {
                        fill=new NormalFill();
                  } else {
                        fill=new ActiveFill();
                  }
                  widthRatio=o.width/fill.width;
                  heightRatio=o.height/fill.height;
                  if (map.getChildByName(o.name+'_fill')) {
                        map.removeChild(map.getChildByName(o.name+'_fill'));
                  }
                  if (widthRatio>heightRatio) {
                        ratio=widthRatio;
                  } else {
                        ratio=heightRatio;
                  }
                  fill.width*=ratio;
                  fill.height*=ratio;
                  fill.x=o.x+(o.width-fill.width)/2;
                  fill.y=o.y+(o.height-fill.height)/2;
                  fill.name=o.name+'_fill';
                  map.addChildAt(fill,map.getChildIndex(o));
                  fill.mask=o;
            }
      }
}


I tested this line: navigateToURL(new
URLRequest('http://google.com'),'_blank,toolbar=yes,scrollbars=yes,resizable=yes,width=750,height=950');

But this isn't opening a specific sized window, specially when you use tabbed browsers (like FireFox, Chrome etc)

That's why I suggested to use Javascript with External Interface.

and for external Interface this how it should go:
function mapClickListener(e:MouseEvent)
{
                  var path:String = 'http://www.flashimap.com/sample-link.php?location='+e.target.name.substring(0,e.target.name.length-3);
                  ExternalInterface.call("openWin", path); // call JS function
}

Author

Commented:
You're going to have to give me step by step instructions on how to do that bro.  Pretend that I'm semi-retarded.  Is everything entered into the .as script?
I may have co-related it with some previous comments.. anyway here's fresh start:

Opening specific sized window from navigateToUrl is not working in tabbed browsers.
So It will be better if you'll use ActionScript in conjuction with JavaScript:

1. I suppose you are embedding your flash SWf in a HTML page (or php, java any), in that page you have to put this small javascript function:
-------------------------------------
<script language="javascript">
function openWin(url)
{
      // here we have specified the window's width and height
      window.open(url,'mywindow', 'width=750, height=950, toolbar=yes, scrollbars=yes, resizable=yes');
}
</script>
---------------------------------
This Javascript function will accept a URL and open a new window with specific width and height.


2. Now we'll make some changes in your AS file's "mapClickListener" function.

------------------------
                     function mapClickListener(e:MouseEvent)
                  {
                  var path:String = 'http://www.flashimap.com/sample-link.php?location=' + e.target.name.substring(0,e.target.name.length-3);
                  
                  //using ExternalInterface to call JavaScript function, and passing url
                ExternalInterface.call("openWin", path);
                  }
-----------------------------------


I hope it will be helpful to you.

Author

Commented:
okay thanks - couple of questions.  Where in my html code do I put the java function?

If you click on the AZ button - it should bring up www.gmlighting.net/repfinder_alaska.html

Do I substitute the www.flashimap.com/sample... with that, and then for the other buttons?
Sorry for late response.

JavaScript function you could write anywhere in HTML, but better to put it under <head> tag.

And yes, you have to replace that path with the original one for every button.

Author

Commented:
Thanks guys!
is this solution working for you?

"first and foremost using "_self" is not going to help.

change it to _blank"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial