View comments | RSS feed

getURL()

Availability

Flash 2. The GET and POST options are available only in Flash Player 4 and later versions.

Usage

getURL(url:String [, window:String [, "variables":String]]) : Void

Parameters

url The URL from which to obtain the document.

window An optional parameter specifying the window or HTML frame into which the document should load. You can enter the name of a specific window or select from the following reserved target names:

variables A GET or POST method for sending variables. If there are no variables, omit this parameter. The GET method appends the variables to the end of the URL, and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for sending long strings of variables.

Returns

Nothing.

Description

Function; loads a document from a specific URL into a window or passes variables to another application at a defined URL. To test this function, make sure the file to be loaded is at the specified location. To use an absolute URL (for example, http://www.myserver.com), you need a network connection.

Example

This example loads an image into a movie clip. When the image is clicked, a new URL is loaded in a new browser window.

var listenerObject:Object = new Object();
listenerObject.onLoadInit = function(target_mc:MovieClip) {
   target_mc.onRelease = function() {
      getURL("http://www.macromedia.com/software/flash/flashpro/", "_blank");
   };
};
var logo:MovieClipLoader = new MovieClipLoader();
logo.addListener(listenerObject);
logo.loadClip("http://www.macromedia.com/images/shared/product_boxes/159x120/159x120_box_flashpro.jpg", this.createEmptyMovieClip("macromedia_mc", this.getNextHighestDepth()));

In the following example, getURL() is used to send an e-mail message:

myBtn_btn.onRelease = function(){
   getURL("mailto:you@somedomain.com");
};

In the following ActionScript, JavaScript is used to open an alert window when the SWF file is embedded in a browser window:

myBtn_btn.onRelease = function(){
   getURL("javascript:alert('you clicked me')");
};

You can also use GET or POST for sending variables. The following example uses GET to append variables to a URL:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
myBtn_btn.onRelease = function() {
   getURL("http://www.macromedia.com", "_blank", "GET");
};

The following ActionScript uses POST to send variables in the HTTP header. Make sure you test your documents in a browser window, because otherwise your variables are sent using GET:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.macromedia.com", "_blank", "POST");

See also

loadVariables(), XML.send(), XML.sendAndLoad(), XMLSocket.send()

Comments


recoveredfromflashMX2004 said on Aug 4, 2004 at 3:03 PM :
rcory said on Feb 2, 2004 at 8:03 AM :

An example using "POST" would be helpful here and links to other places where "POST" is an option.


mmm..beefy said on Mar 5, 2004 at 8:24 AM :

I agree. This help file is a bit lacking in that there is nothing said about HOW to use the variables parameter.


jepo said on Mar 25, 2004 at 4:55 PM :

Thanks! A couple of new examples have been added for this entry, which will be available in the next Help update.


No screen name said on Apr 10, 2004 at 7:33 PM :

Hey i am just trying to figure out how to build a simple Flash form. I have existing coldfusion code, and i'd like to create a log in form in flash and have th input_text fields work just as they do in html. I have made a simple form and every time i try ot submit these using post or get nothing works. I know the events are working correctly because when i click on my submit buttong i show up in my desired page. It is just that i can't figure out how to send data though. Can an example be made on this. I can't find one anywhere online.


siyan1229 said on Apr 14, 2004 at 12:53 AM :

simple example:

on(press){
var myVar = "test";
getURL("http://localhost/printVars.php","_self","POST");
}

printVars.php:
<?php
foreach($_POST as $key => $value){
echo $key . " : " . $value . "<br>";
}
?>


Mister Neb said on Apr 15, 2004 at 7:35 PM :

Moock's book has a nice list of all the things you can do with getURL (http, mailto, file, Director stuff, etc).


No screen name said on Apr 16, 2004 at 6:31 PM :

I have created a presentation & when I use the GetUrl, on my computer it opens a new brower window on top, but I am hearing complaints from others that it is popping up behind the presentation. Is there a fix for this?
recoveredfromflashMX2004 said on Aug 4, 2004 at 3:04 PM :
isaac dealey said on Apr 20, 2004 at 10:17 PM :

yes there is a fix, but the issue isn't with flash -- add this to your html in the popup page <script language="javascript"> window.focus();</script> this will bring the popup page to the front.


jafo said on Jun 22, 2004 at 4:20 PM :

siyan1229's example works. Here are a couple of notes that I'll add. I'm using Flash 2004 Pro. It seems that all three parameters are required if you want to specify the METHOD as shown in siyan1229's example. You could also just include the GET variables in your URL if you want, but Flash will automatically encode your URL variables if you use the GET METHOD.

Also, I believe Flash will send along, using GET or POST, all variables in the _root level of the swf. I haven't fully tested that, but that's what appears to happen so far.


nokonet said on Jul 2, 2004 at 5:25 AM :

I have created an .exe file in full screen and use the getURL to open html documents. I placed the window.focus() in my html. It´s still showing the html file on the back. Any idea?
larkydoo said on Aug 9, 2004 at 3:32 PM :
I'm using the following actionscript in a flash movie:

getURL("help/help" + helpFileNum + ".html", "helpWindow");

It opens the browser and loads the file correctly, depending on the value of helpFileNum, but opens a fresh window with each new instance of helpFileNum. That is, it will open help1.html in a window, let's call it window a. Then when helpFileNum is 2, it will open help2.html in a new window, let's call it window b. Then when it tries to open help1.html again, it will open it in the first window it opened, i.e., window a again. This is not the expected or desired behavior. Anyone else having this issue?

I'm using Flash 2004 Pro, if that makes a difference.
Flash Tools said on Aug 20, 2004 at 2:14 AM :
Hi! I'm trying to open a new browser window from a flash button, but i want this windows to be a cromless one.
I mean, from javascript i use:
windows.open(<URL>, <winName>,"scrollbars=0, fullscreen=1");

But calling this sentence from a getURL, seems not to work.

thanks in advance
areohbee said on Oct 28, 2004 at 3:07 AM :
I concur the GET/POST sends all variables from the root timeline, not unlike how FlashVars populates variables in the root timeline from URL query string in URL invoking an swf file.

I would just like to add here for you folks contemplating usage of POST to read the tech notes and comments at the support center as POST may not behave as expected.
McUsher said on Oct 29, 2004 at 5:21 AM :
There should be a note in this doc about getURL("javascript:.... concerning IE:
the string called by getURL may only be 508 Chars long, including the word "javascript" etc.
There is no limit, if that string starts with anything else, but "javascript" or if the html-page containing the .swf is within a frameset.

No 508 Chars limit with FireFox..
Testes with IE 6/5.5
Flash MX / Flash MX2004
Flash Players 6/7
nShar said on Dec 22, 2004 at 5:06 AM :
referring to comment by
siyan1229 said on Apr 14, 2004 at 12:53 AM

Is it possible to use this code with the button component - because it doesn't appear to work for me.

Can we have an example using the button component please
(Like a form that sends email info to an email sending script)

Thx
IFDNRG.com said on Jan 19, 2005 at 7:05 AM :
Hi all - i just came across the 508 char limit with javascript, on getURL too. Please can someone drop this in the official documentation so that people aren't wasting their time figuring out what the heck is wrong :0 Thanks :)
Francis Cheng said on Jan 19, 2005 at 8:12 AM :
Thanks for the suggestion. I've added a note about the 508 character limit to the JavaScript example in the source file.
meni56 said on Jan 20, 2005 at 8:04 AM :
Hi
There is a big problem in xp2 you can't open a widow direct from flash
also you can't do a link to download with because xp2 will blocked the download.and if you will confirm it will do a refresh to the page
Francis Cheng said on Jan 21, 2005 at 1:00 PM :
Hi meni56,

There is a section on the Macromedia website devoted entirely to issues with Windows XP Service Pack 2:
http://www.macromedia.com/support/service/servicepack2.html
Daniel and his dog said on Jan 31, 2005 at 12:32 PM :
Jumping from player to anchored page

I found this to work smoothly:

getURL("dir/dir/page.htm"+"%23"+"3", "main");

as a substitute for

getURL("dir/dir/page.htm#3", "main");
No screen name said on Feb 4, 2005 at 10:43 AM :
try this:

set your default browser to firefox (possibly others)

put this in frame one of a blank actionscript and run your movie:

getURL('javascript:testing("test test");');

a browser window opens - good, the javascript was called.

okay try this:

getURL('javascript:testing("test test test");');

what? no window?

this however works:

getURL("javascript:testing('test test test');");

problem is if you want to pass a string with embedded single quotes...

this behaviour is not observerd with internet explorer (all forms work) what is going on?
No screen name said on Feb 21, 2005 at 1:39 AM :
Dear Flash developers...

I have a big problem with the getURL() function. The getURL function actually performs a HTTP Request to the browser. Is there a way to avoid this?
I need to trigger a JavaScript function in my HTML document from within my Flash Movie WITHOUT initiating a HTTP Request. Is this posible? Does the FSCommand trasparently uses the getURL function?

Thanking you in advance.

Jason
murk379 said on Mar 6, 2005 at 5:53 PM :
All,

I have two functions, one opens a new small browser window for file upload, the other opens a File Download box on top of the current window.

The first function (file upload) calls a javascript function embedded in the html of the page, like this:

getURL("javascript:OpenWindow("+ url +", 'toolbar=no,scrollbars=no')", "_self");

Where 'url' is the url of a server-side page with a simple HTML file upload form on it. We want those toolbar=no (etc) parameters to be passed through to the javascript so it can use them when creating the new window (toolbars on a file upload window is just icky).

Our second function opens a File Download box on top of the current window. It is a simple call to getURL(url, "_self");

Where 'url' is the url of a server-side script that emits appropriate header information and the contents of a file. Both of these functions work beautifully on their own.

When used in combination, however, they don't. From my tests, opening the File Download box always works, but after the first use of this function, further calls to the file upload function fail to raise a new browser window. In fact, any attempt to use the "javascript:" scheme (such as the "javascript:alert('hello')" example above) fails.

Has anyone encountered this before, and more to the point, does anyone please know of a workaround for this?
murk379 said on Mar 6, 2005 at 5:55 PM :
Further to my comment above, I am testing for clients who use WinXP with SP2.. I am thinking it may be a SP2 issue?
bmriley said on Mar 8, 2005 at 9:14 AM :
I had the same issue with requesting synchronous JS via getURLs...I did a ton of tetsinmg and came up with a Queue class. After getting the fix in my app, I decidde to research the issue a bit more, witht he idea that someone else must have had this issue...low and behold...

http://www.macromedia.com/devnet/flex/articles/analytic_app_05.html
murk379 said on Mar 8, 2005 at 1:21 PM :
Hi bmriley

Thanks for the interesting piece of info... unfortunately the problem I have is not quite the same.

My problem is this: calls to getURL() with a target of _self appear to break subsequent javascript calls to the browser. I have managed to reproduce the suspected bug in a small testing fla file.

To clarify, referrin to my post above: the first call to getURL() (without using the javascript: scheme) and a target of "_self" seems to put the browser into an odd state where further getURL() calls that *do* use
the "javascript:" sceme fail to execute.

The GetURLQueue class you mention prevents multiple getURL requests within the same playback frame, whereas for me the problem occurs no matter how much time I leave between the non-javascript call and subsequent javascript: schemed calls.
No screen name said on Mar 29, 2005 at 10:11 AM :
The getURL function seems to url escape the parameter names. I need to pass a parameter name ".done" but this comes out escaped, as "%2Edone" and the server side doesn't un-escape the params. is there a way to turn off escaping on the parameter names?

I want to use a post instead of a get (where i can force the param name) because i don't want parameters appearing in the location bar.
gtodd said on Apr 14, 2005 at 4:01 PM :
Any ideas on how to send a user back to a previous URL?
No screen name said on Apr 18, 2005 at 12:00 PM :
Hi,
When I try to call a javaScript function using getURL("javascript:... from a movie in _level2, it doesn't work, but it works if I call it from _level0. Anyone know why?
Thanks
Nathan
No screen name said on May 19, 2005 at 4:16 AM :
Are the calls synchronous or asynchronous?
No screen name said on Jun 3, 2005 at 6:04 AM :
Why is it that the getURL functions works fine in loading programs or scripts when using the Internet Explorer browser, but is unable to do so when using Mozilla?

Internet Explorer actually opens the script or program. Whereas, Mozilla loads scripts and programs as web pages (displays contents of .bat files on a new empty page with getURL("script.bat", "_blank")) instead of just executing them. I tried changing the Mozilla preferrences but if you make it so that .bat files are loaded by cmd.exe, then cmd is intiated from the Mozilla directory and not the directory of the script and none of the commands in the script are run. With running programs, it tries to open programs with other executables thinking that they're ppt or doc or something.

Any suggestions or ideas in getting this to work or in loading scripts or programs in Flash in general would be great. I've tried fscommand and that won't work either because my application has to be in a browser, and I'm not sure if Flash's JSAPI C-level extensibility mechanism will work either because I'm writing this application for the Solaris platform, and only Windows and Mac are mentioned regarding compatibility.

Thanks in advance,
Rob
redskin87 said on Jun 9, 2005 at 8:37 AM :
I am having an issue with the getURL("javascript: ...") on some versions of IE. I have a test movie that calls getURL("javascript:alert('hi');", "_self") on (release) of a button.

It seems to work just fine, EXCEPT under the following conditions:

1) IE6 under Win2K (seems ok on my WinXP-SP2 machine and even in Firefox on my Win2K box)

-- and --

2) the hmtl containing the swf is in a frame (works fine if not framed)

-- and --

3) the html containing the swf is not on the same domain as the frame.

Any ideas? I'm stumped. Thanks.
euripides said on Jun 15, 2005 at 11:45 AM :
How I can doit that de acction script geturl open in my webpage in a especific frame. for example I have my webpage div in 3 frames (left, mainframe, botton) i need that the menu (flash object) in the left frame open the new link in the mainframe.
Thanks.
selbadawi said on Jul 14, 2005 at 12:07 PM :
I am trying to getURL "index.aspx?id=about", but it only retrieves "index.aspx". Does anyone know why this is the case?

Thanks
RissaK said on Jul 15, 2005 at 5:53 AM :
Having same problem as selbadawi -- query string doesn't even show up in the address bar when using IE, but works perfectly in Mozilla.

Have posted a question on FlashKit about this. Will share results if I get an answer.
RissaK said on Jul 15, 2005 at 7:19 AM :
no-one answered my post on FlashKit, but I came up with a solution, using javascript in my getURL action, as follows:

on (release) {
getURL("javascript:window.open ('id_theft/idtheft.htm?myBroadband=true', '_blank'); void(0);");
}

This will FORCE IE to stop truncating the query string. Still don't know why it wasn't working the way it SHOULD, but this javascript workaround does the trick.
RissaK said on Jul 19, 2005 at 12:16 PM :
Why didn't I think of this before?

If I use URL-encoding for the question mark, the string passes just fine. Much simpler solution than my previous one.

[code]
on (release) {
getURL ("id_theft/idtheft.htm%3Fbroadband=true");
}
[/code]

Doh!

However, I could swear that you didn't have to do that in previous versions of Flash... could be hallucinating, though.

l8r
ufitzi said on Jul 20, 2005 at 11:32 AM :
Well, I have to assume many of these problems are related.
Here's my issue, which is similar to posts above by:
redskin87 && McUsher, although the 508 char limit is not my problem.
.....
the following code works fine (IE and Mozilla based browsers) if my content frame is on the same domain as my frameset:
getURL("javascript:details(" add this.id add ");");

Once I create a frameset on another domain, and pull the content frame w/ Flash and JS into the new frameset, IE does not invoke the JS function. Period. No errors, nothing.
I was thinking some sort of Flash Player 7 security feature, but it still works fine in Firefox.
Then I thought it must be an IE security issue, but if I put another test JS function on my content page, and invoke it using an <a> tag from the external frameset, the function gets called and executes as expected.
SOOOOOOOOO, maybe it is a combination IE/Flash Player bug.

I'm at a loss.
Good luck, folks!!

bh
No screen name said on Sep 8, 2005 at 4:13 AM :
The problem lies in a IE bug that mis-identifies frames. use the "_top" target to get the getURL going....
Chipmonk77 said on Sep 29, 2005 at 12:27 AM :
Hi!

I have just met that WinXP SP2 bug that prevents Flash Player to open a new html window. I read the documentation by Macromedia, but the only thing they adviced is to change the pop-up settings of IE.

Is it serious, that if I want my webpage to download a file, I have to write a message to the user, that: "please, would you be so kind as to set your pop-up settings to low? You can do it by clicking ..." etc.??

This mustn't have the only solution. I've been searching on the web for days, but I haven't been able to find a simple solution to this VERY simple problem. I want to download a file.
Please, help. :)
No screen name said on Nov 25, 2005 at 8:45 AM :
good job, RissaK!!
Just look at this example to open a popup WITHOUT any Javascript function... so.. I prefer use flying DIVs.. cause there are many antipopups. In this code, you can use some params and the window will open at the center of the screen... I hope it helps anyone!!

on(release){
pPagina = "geturl.htm";
pWindow = "winname";
pWidth = 300;
pHeight = 300;
pParams = "width="+pWidth+",height="+pHeight+",left='+(screen.width/2-"+(pWidth/2)+")+',top='+(screen.height/2-"+(pHeight/2)+")+',toolbar=no,scrollbars=no,resizable=no,menubar=no";
getURL("javascript:window.open('"+pPagina+"','"+pWindow+"','"+pParams+"');void(0);");
}
No screen name said on Nov 25, 2005 at 9:03 AM :
Ok, if you want to use another solution for the Popups you can try this:

- A flash movie inside a DIV tag over the page with a "close button"

First create a DIV tag in the document and put the flash object inside it like this:

<div id="flashPopup" style="position:absolute;left:0;top:0;width:500px;height:300px;z-index:1;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="500" height="300">
<param name="movie" value="swfs/pop_file.swf" />
<param name="quality" value="high" />
<embed src="swfs/pop_file.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="500" height="300"></embed>
</object>
</div>

ok... now put this Javascript functions in the Head tag:

<HEAD>
...
<script type="text/javascript">
function getObj(){
return document.getElementById(getObj.arguments[0]);
}

function closeFlashPopup(){
oFlash = getObj('flashPopup');
if(oFlash)oFlash.style.display='none';
}

function centerFlashPopup(popWidth,popHeight){
oFlash = getObj('flashPopup');
if(oFlash){
oFlash.left=window.availWidth/2-popWidth/2;
oFlash.top=window.availHeight/2-popHeight/2;
}
}
</script>
</HEAD>

good boy... now at the first frame of your movie put this code to center our "div flash window" in the page (don't forget the Width and the Heigth:

getURL("javascript:centerFlashPopup(500,300);");

To finish our solution, now we'll create a button to close the "div window"(turn it invisible)...
put this code in the button:

on(Release){
getURL("javascript:closeFlashPopup();");
}

Well done!!!

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001360.html