Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » as » getURL in Actionscript 3

getURL in Actionscript 3

One of the bigger changes in Actionscript 3 is the way in which you call a link.

Flash 9 has been out for a few weeks now and Actionscript 3 is all the rage, but some things have started to confuse people. One of those is where getURL() disappeared to.

The old way (Actionscript 2) was to do it like this.

getURL("urltoload", "target");

In Actionscript 3 there is a little more to it.

var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
  navigateToURL(request, '_blank'); // second argument is target
} catch (e:Error) {
  trace("Error occurred!");
}

The more obvious difference is a call to the URLRequest class and pass that response into the navigateToURL() method.

Now if you wanted to rig this call to a button you would just set up a simple Event handler

movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
  var url:String = "http://site";
  var request:URLRequest = new URLRequest(url);
  try {
    navigateToURL(request, '_blank');
  } catch (e:Error) {
    trace("Error occurred!");
  }
}

Tip: If you wanted to use this example in Flex or an all Actionscript project you would want to include the necessary classes.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: getURL in Actionscript 3

 Kris Hunt  Thu Jun 14, 2007 6:15 am  
Where do you assign the target in the ActionScript 3 code?
 mkeefe  Thu Jun 14, 2007 8:02 am  
The second argument in the navigateToURL() method, such as:

navigateToURL(request, '_blank');

You can also use "_self", "_parent" or "top"
 Phatmany  Thu Jun 14, 2007 10:30 am  
I tried using the code above to assign the target so it does not open up a new browser for my link but it doesn't work.
Can someone tell me what I did wrong?
 mkeefe  Thu Jun 14, 2007 11:43 am  
Did you set the target to "_self"?
 zay  Mon Jul 2, 2007 11:38 pm  
You also missed a quote at the end of the trace, should be
trace("Error occurred!");
 mkeefe  Tue Jul 3, 2007 7:26 am  
Oh your right, I didn't test this code and look what happens. haha

Thanks for letting me know.
 Tom  Sat Jul 7, 2007 6:45 am  
How would you set it to open a window at a specific size?

Width = 500
height = 500

or is it back to calling Javascript for this?

Thanks
 Peter  Fri Jul 20, 2007 6:14 am  
I'm trying to make this work on a button – used to be much easier with the getUrl function! Question: where does the second block of code (calling a movieclip to act as a button and link to a url) go? I can't attach it to the movieclip, obviously, so I have tried putting it in it's own code layer.

Love some help, any tips?
 Haydn  Sat Jul 28, 2007 4:31 am  
@Tom:

Yes, you'd have to use Javascript to specify a window size.
 Spencer  Wed Aug 15, 2007 8:13 pm  
I'm getting this error message.

1084: Syntax error: expecting leftparen before colon.
 Spencer  Wed Aug 15, 2007 8:13 pm  
I'm getting this error message.

1084: Syntax error: expecting leftparen before colon.
 mkeefe  Wed Aug 15, 2007 11:55 pm  
For some reason the code parser destroyed the function, it reads like this:

function callLink:void {

but should be,

function callLink():void {

Hope that helps.
 unreal  Sat Aug 18, 2007 11:56 am  
I like how it went from a simple code to a huge retared paragraph of programing...

Nice job Adobe!

 Paul Thomas  Fri Sep 7, 2007 11:36 am  
I keep getting this error..

ArgumentError: Error #1063: Argument count mismatch on buttonpractice_fla::MainTimeline/callLink(). Expected 0, got 1.
 Jonno  Tue Sep 11, 2007 3:39 am  
Put the mouse event in to fix above prob.

function callLink(event:MouseEvent):void {
 Chris  Tue Sep 11, 2007 10:17 am  
I am so upset with Flash CS3 . Whatever happened to K.I.S.S.

This is another example of making things overtly complicated to increase revenue on Aftermarket training.

getURL("url"); had to become a mess didn't it. Making my job frikin tough. Already waste three hours trying to figure out why this doesn't work and still at a lost.
 Chris  Tue Sep 11, 2007 10:20 am  
Sorry Try this it actually works and is alot more elegant

myButton.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://flashgameu.com");
navigateToURL(request);
}
 mkeefe  Sat Sep 22, 2007 4:21 am  
@Chris, The "try" is used to silence errors when the URL isn't found.. also you should not place the URL to call within the function.. a better option would be to wrap all this code in a function with url/target as arguments.
 Guest  Fri Sep 28, 2007 1:32 pm  
HI

Anyone knows to get paramas, class and rel from a getURL to html? the right way?
See: http://www.datavraag.nl/sonic/

The image is link itself and triggers a window box internally. But how can I trigger the same ling from getURL actionscript 2 style with the class/params and if possible the rell param.

Any help/link is helpful!
Valentijn
o n t w e r p AT z o n n e t . n l
 SunBlue  Thu Oct 4, 2007 9:32 am  
HI

i'm new to action scripting 2. i'm trying to activate a movie clip to enable the user to send an email to the adress in the line of text. prob: it's a yahoo adress.

this is what i'm using:

Link_Email.onPress = function ()
{
getURL("mailto: griot5@yahoo.com")
}

What am I doing wrong?
 oliver  Tue Dec 4, 2007 4:47 am  
how about get/post methods?
 zerostar  Fri Jan 4, 2008 12:14 pm  
Heya :)

I've encountered a head-jamming problem with passing link targets from an XML > Flash > back-to-the-browser-window with AS3. Essentially, I am using grey box (javascript ajax window layer) to pop up a flash movie and then I need the links to go to _top (in order to escape from the grey box js window).

the problem I have is all of the images and links are coming from the external XML file (not from with the .swf), so the target code is just _top.

A normal ...target="_top"... works to move out of the gbx window from an HTML link (if the window's content was in a non-XML/Flash embedded page)

Do you know how to pass this target information from the XML document through the flash movie?

If not that's cool - just twisting my brain around trying to make this work atm...

thanks :)
 Scotter  Fri Jan 18, 2008 12:00 pm  
I'm confused because the URL is within the function in the following code:

myButton.addEventListener(MouseEvent.CLICK, callLink);

function callLink(event:MouseEvent):void {
var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
}
}
 Mike  Wed Jan 23, 2008 3:19 pm  
I agree. Adobe is sucking more every year. Their software update is poor every year. They charge more and more for crumbles. Flash had virtually no update in functionality since they bought from Macromedia. The only update was to this sucking ActionScript more complex every second. I mean complexity without purpose, as the complexity had no extra gain. Adobe do not have any competition. They have so much software doing the same thing that they are limiting packages so one do not overlap the other. This is why you have Photoshop with smartlayers and smartfilters instead of having the sucking thing like After Effects. This is why Photoshop cannot edit audio. The whole crap stinks.
 mkeefe  Wed Jan 23, 2008 3:50 pm  
@Mike,
I am not sure what you are referring to, but Flash CS3 was the introduction to the most powerful version of ActionScript. I agree that updates come slower than normal, but often times that is the result of extended testing.

Also, overall I am not sure what relevance your comment has on the article, but I will leave it, as it is an interesting discussion.
 mkeefe  Wed Jan 23, 2008 3:52 pm  
@Scotter,
The URL is within the function in this example, but you could easily pass the URL via an argument, which would make the function more dynamic and re-usable.
 Tomek  Mon Feb 4, 2008 9:03 pm  
This is my AS:

button_cz. addEventListener(MouseEvent.CLICK, myButtonFunctionCZ);
function myButtonFunctionCZ(event: MouseEvent {
var request:URLRequest = new URLRequest("http://blog.tomekson.com/");
navigateToURL(request);
}

But it opens the target in new window. When I modify it to

navigateToURL(request, '_self');

it doesn't work. I get "SecurityError #2137: Security sandboxviolation. Can you please help me? I want to open it in the same window. Thanks
 planet  Tue Feb 5, 2008 4:31 am  
I can get the _blank to work (opens new page) but _self or even _parent do not work, does nothing?

Must have something to do with the JS script to embed in page, if I use old way it works?
whats up?
thanx
 Chris Rywalt  Wed Feb 6, 2008 11:41 am  
Good God but ActionScript 3.0 bites. It's really, really horrible.

But thank you for this page -- it's the first thing I found that helped me get a link from Flash actually working.
 mkeefe  Wed Feb 6, 2008 12:05 pm  
@Tomek - Is the URL and the SWF on the same domain?

@planet - Do you get any errors?

@Chris - Curious, what did you dislike about ActionScript 3?
 Chris Rywalt  Thu Feb 7, 2008 3:17 am  
I'm a Perl programmer -- really, I'm a programmer in general. I've used Basic, Fortran, Pascal, Prolog, Lisp, C, Java, Perl...you name it, I've probably at least played with it. Since JavaScript and PHP, though, it seems that a lot of languages have been designed by people who apparently know nothing about programming. ActionScript is more of the same. It's impenetrable and needlessly complex. The expansion from ActionScript 2 to 3 you explain above is a perfect example.

Partly I'm just annoyed because, despite all my background in programming, it took me over two hours to make an image link to a Web page using Flash. I suppose if I keep working with it I'll get less annoyed.
 Danielle  Fri Feb 8, 2008 6:14 am  
First I want to start off by saying as an early adapter of flash (Flash 4 - yikes!) and a front-end programmer, I love AS3. It's much more powerful and much more of a programming language and a simple animation tool. Unfortunately and unfortunately this makes many of us front end programmers have to brush up on our CS skills.

Second, I have a bit of an issue that someone may be able to help with. I am trying to do a paginated navigation from and xml query. For example my xml has 298 element spread out across 10 query strings so 1-10 of the elements are here:http://www.xxx.com/my/xml?start=0, hitting next would load the next 10 -www.xxx.com/my/xml?start=10. How would that be and can it be written in the "var request:URLRequest"

Thanks for these posts!
 mkeefe  Fri Feb 8, 2008 6:17 am  
@Danielle - In order to create a paginated response you would want to create the two buttons, attach them to a CLICK event for next/prev and pass in the offset value to the URLRequest each time. As a "simple" way you could of course use HTML code in a textbox, but Flash buttons would look much cleaner.

I will try to write up an article on this very subject.
 Danielle  Fri Feb 8, 2008 6:57 am  
Thanks so much. Working on the flash solution you stated but an article would also be much appreciated.

Thanks again.
 Kevin  Sun Feb 10, 2008 3:02 pm  
This code works...opens in same page...

[code]button1.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://www.msn.com/");
navigateToURL(request, "_self");
}[/code]
 BarTheZ  Mon Feb 18, 2008 1:42 pm  
Allrighty, so far this article has been a huge help for me; as well as this video from Adobe.
http://www.adobe.com/designcenter/video_workshop/?id=vid0130

Anywayz, I've finally got my first button to link to a page... and now... My button stops working... :) no more hovering... it's just - dead, and when I remove the actionscriptcode (which I've put into a layer above it) it works again...

you can check it out here - http://www.shiatsumarl1.be/menu.swf
it's giving me quite a headache by now, so hope you guys can shine some light on this one too...
only the "Shiatsu"-button is clickable by now, and normally it should be giving the same effect as "BachBloesems" next to it... :/

thx in advance...

btw this is the code I've added;

shiatsub.addEventListener(MouseEvent.CLICK,myButtonFunction);
function myButtonFunction(event:MouseEvent):void {
var request = new URLRequest("http://www.shiatsumarl1.be/shiatsu/");
navigateToURL(request,"_self");
}
 Rue  Tue Feb 26, 2008 1:52 pm  
Ok, so I've successfully used the AS3 URLrequest function on one button in my flash piece but when I try to add the same function to a different button in the same file i get an error 1021. duplicate function definition
function callLink(event:MouseEvent):void {
 Joe  Tue Mar 11, 2008 10:18 am  
@ Kevin Sun Feb 10, 2008 8:02 pm :::

that doesn't work for me .. nothing happens .. but when i change to "_blank" then click works but in new window ..

here is my code::

[code]button.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://www.grandforks.com/directory/?page=main");
navigateToURL(request, "_blank");
}[/code]
 mkeefe  Tue Mar 11, 2008 10:34 am  
@Rue, you would only want to declare the function once, and then pass in the url/target to open.

@Joe, The _blank would certainly open a new window, but it sounds like _self is not?
 JC  Wed Mar 19, 2008 8:08 pm  
Thanks Kevin Your suggestion was very helpfull. I had like two weeks trying to make this work. Thanks a million
 JC  Wed Mar 19, 2008 8:13 pm  
To Joe, Joe remember to name your Instance if your button Instance is not button it wont work. also try to give an unique name for eventListeners for different buttons. I hope this helps.

 kala  Mon Mar 24, 2008 8:09 am  
does anyone know what script i need to have my buttons open pdfs in a new window?
 JoelSeph  Tue Mar 25, 2008 11:26 am  
I would have to agree with Chris. There is nothing about AC3 that is intuitive at all. The syntax is a nightmare, you basically have to memorize function names, keywords, and argument counts. It really doesn't fit into the intuitive nature of the Flash GUI whatsoever. It may be powerful, but unless you program exclusively in AC3, it's like going to France once a year, you have to relearn it every time you use it. Blah.
 JoelSeph  Tue Mar 25, 2008 11:29 am  
Blah! :%s/ac3/as3

hehe
 mkeefe  Tue Mar 25, 2008 12:00 pm  
@JoelSeph, I am not sure I understand your dislike with AS3, but it I do know it is much different than its predecessor (AS2).

Different in my opinion is not a bad thing, just means you have to relearn things.
 WOOHOO  Thu Apr 17, 2008 6:42 am  
Nice post. this saved my life thanks!
 remas  Mon Apr 21, 2008 4:16 am  
i wanna link to a .exe file in AS3. can anyoen help me plz
 mkeefe  Mon Apr 21, 2008 5:40 am  
You could use fscommand to call an EXE, but other than that ActionScript 3 really doesn't have much control over them.

The alternative is to use Zinc or something similar which wraps the SWF in a regular programming container.
 David  Fri Apr 25, 2008 10:35 am  
I have the same problem as Tomek back on Feb 5th. I receive the error:

SecurityError: Error #2137: Security sandbox violation: http://s.guildomatic.com/5187/host/bc/bc7fdac97e0e55167241a8b0ff86b8f1.swf cannot navigate window _self within http://finalrequiem.guildomatic.com/ (allowScriptAccess is ). Attempted URL was http://finalrequiem.guildomatic.com/raids.
at global/flash.net::navigateToURL()
at MainBanner_fla::MainTimeline/raids()
 David  Fri Apr 25, 2008 10:38 am  
the .swf and the page being linked to are on different domains.

swf is on http://s.guildomatic.com and the link is to http://finalrequiem.guildomatic.com
 mkeefe  Fri Apr 25, 2008 10:45 am  
The SecurityError your experiencing will stop if you modify the object/embed tags:

<embed allowscriptaccess="always" allownetworking="external" ..

Hope that helps,
Matt
 jonathon  Thu May 1, 2008 11:38 am  
Matt,

Can you provide a working example of passing a URL via an argument?

The code (after reading all of the above) resulted in the following (which works for me once uploaded, but for some reason opens two browser windows when tested locally):

homeBtn.addEventListener(MouseEvent.CLICK, callLink);
function callLink(event:MouseEvent):void {
trace("callLink activated");
var url:String = "http://www.google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
}
}

Ideally, I'd like to set up a
var homeURL:String = "http://www.home.com";
var contactURL:String = "http://www.contact.com";
etc.

and have that sent by
homeBtn.addEventListener(MouseEvent.CLICK, callLink(homeURL));
and
contactBtn.addEventListener(MouseEvent.CLICK, callLink(contactURL));

to

function callLink(incomingURL):void {
var request:URLRequest = new URLRequest(incomingURL);
etc...
}

That, to me, is intuitive to my previous programming experience and I'm thrown for a loop by the whole

event:MouseEvent):void

scheme of things. I expect variable names rather than event:MouseEvent within the brackets. Unfortunately, that doesn't work.

This example shows why I don't like AC3. Kudos for it being more powerful, but in this particular example, a simple getURL command is what I need 99% of the time and works 100% of the time. The added definitions and function seems far too complex for such a simple operation, IMHO. I wouldn't be surprised if a lot of my frustration is due to lack of education on the matter, but seeing as how I can't find a working example of how to pass a URL value to a function in Flash's help, my available education isn't enough.

That's where this site has come in :)

Thanks for your help!
 mkeefe  Thu May 1, 2008 1:36 pm  
@jonathon, Rather than try to explain the workflow as a comment I have branched this topic out into a new tutorial.

Opening Url In ActionScript 3 dynamically

Let me know if that answers all your questions.

In regards to not liking AS3, all I can recommend is to stick with it. In time it will make sense and you will be better off. Just ask other AS3 developers. :)
 tetaniwha  Sun May 4, 2008 3:16 am  
Got my links going using the below script.

- replace "homebutton" with the name of the instance name for your button (Must do)

- change URL to your target

Im a MCSE-guy so not impressed with the complexity of the scripting. Especially just to link to another webpage. Took me all day to get it going and wouldn't of done it without this forum

Cheers all

homebutton.addEventListener(MouseEvent.CLICK, homebuttonFunction);
function homebuttonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://tetaniwha.zapto.org/default.asp");
navigateToURL(request, "_self");
}
 cyanowski  Wed May 7, 2008 11:53 am  
@Rue, you would only want to declare the function once, and then pass in the url/target to open.

what would this look like when applied to a button? here's what i have now (sorry to be such a noob):

Bayview_btn.addEventListener(
MouseEvent.CLICK,
function(evt:MouseEvent):void{
var request:URLRequest = new URLRequest("http://goodnuznozmind.blogspot.com/") navigateToURL(request);
}
);

p.s. in future will do this using the other tutorial you wrote!
 Elitro  Tue May 13, 2008 10:14 am  
Even with "_self" added it keeps opening a new tab be it in Firefox or IE, it's driving me crazy!

Is there any way to get it oppening on the same tab? help would be greatly appreciated
 mkeefe  Tue May 13, 2008 1:18 pm  
Can you post your code?
 Elitro  Wed May 14, 2008 4:44 am  

function gotoPage(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest("_root.../principal.html");
navigateToURL(targetURL, "_self");
}

function init():void{
principal.addEventListener(MouseEvent.CLICK, gotoPage);
}

init();


I've tried alot of codes all over the internet and i can't get it working even thou i see people saying it works, it should work in firefox right? or perhaps only works on browsers with no tabs? Thank you for your time.
 mkeefe  Wed May 14, 2008 5:19 am  
It is possible that you might have Firefox set to open "All links in new tabs". Reason being that "_self" works just fine here and for others.

Hope that helps.
 Elitro  Wed May 14, 2008 10:32 am  
That's not the case =) and it does the same for IE as well. But thanks for the tip.
 dmoe  Thu May 15, 2008 6:15 am  
Just to say thanks for this, as others have said, you're a life saver!
 PJN  Fri May 16, 2008 8:15 am  
Can you post an example of calling a javascript function. When I run the following, nothing happens in the browser window. I thought maybe it was a security issue testing on local computer, so I also movied it to a web server, but got the same results (nothing happened).

cancelCMD = "javascript:alert("test");";

cancel_btn.addEventListener(MouseEvent.CLICK, cancelBtnPress);

function cancelBtnPress(e:Event):void {
var cancelButtonURL:URLRequest = new URLRequest (cancelCMD);
navigateToURL(cancelButtonURL);
}
 mkeefe  Fri May 16, 2008 8:16 pm  
@PJN, try:

var cmd:String = "javascript:alert('sample');";
navigateToURL(new URLRequest(cmd));
 Olivier  Thu May 22, 2008 1:00 am  
Its better to not use url requests for javascript anymore, instead you should look into externalinterface.call this is the 'new' way to adress javascript funcs, for the above alert the code would be:

ExternalInterface.call("alert", "sample");

First argument of the call is the name of the function you wanna run, any arguments after that get feeded to the func.

For everybody still hating as3, give up, and get into learning it, i had some serious issues with it myself, now like 4 months later i actually prefer as3 over as2 and as1, theres some things that could have been done with less code needed from us developers, but the bucketloads of additions (wich lots of peopel fail to see) make up for that very well imo
 William  Fri May 23, 2008 4:55 am  
I am confused and have no previous experience with Flash. I put this code on a button in Flash

home.addEventListener(MouseEvent.CLICK, callLink);
function callLink: void {
var url:String = "http://www.test.co.uk";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
}
}

I check the code and i get this:

1084: Syntax error: expecting leftparen before colon.
1084: Syntax error: expecting identifier before leftbrace.
1084: Syntax error: expecting rightparen before leftbrace.

I really have no idea what i am doing and when i put this on a web page nothing happens..

Thanks :D
 mkeefe  Fri May 23, 2008 5:48 am  
@William,
The ActionScript (code) would be added to a frame, not directly on a button. :)

The errors your referring to are saying the various characters ),],}

Hope that helps.
 mars  Wed May 28, 2008 4:49 am  
function gotoPage(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest("http://www.yourlink.html");
navigateToURL(targetURL, '_parent');
}
butL.addEventListener(MouseEvent.CLICK, gotoPage);

function gotoPage2(event:MouseEvent):void
{
var targetURL2:URLRequest = new URLRequest("http://www.yourlink.html");
navigateToURL(targetURL2, '_parent');
}
butR.addEventListener(MouseEvent.CLICK, gotoPage2);
 Steve  Thu May 29, 2008 2:05 pm  
Great stuff. Very helpful. Great responses to questions which are also very helpful.

In order to better understand my question, it helps to know that the project I am working on is to be completely contained on a CDROM. I'm using NavigateToURL with a query string but no javascript in order to avoid a security alert. The sandboxType is 'localWithFile'. I'm building this in Flex and setting the additional compiler arguments: -use-network=false

Whether I use a relative path or an absolute path (starting with file://), everything works fine on ALL browsers EXCEPT Internet Explorer 6. Internet Explorer 6 is dropping the query string.

I have noticed that Internet Explorer 6, unlike all other browsers, does not display "file://" in front of a local file. After having tried everything else, I'm exploring this peculiarity.

Any solutions or ideas would be appreciated.
 mkeefe  Fri May 30, 2008 9:49 am  
@Steve, Does IE display an error or "error loading page" warning?

I am not familiar with this issue but another alternative is to use ExternalInterface. Don't see a reason why that should throw a warning..
 Garrett Hestla  Fri Jun 13, 2008 7:00 am  
I have a button that when clicked needs to open a url in another window. In CS2 this was obvious. How do I do it in cs3? I can't apply actionscript to any buttons in cs3.
 mkeefe  Fri Jun 13, 2008 10:12 am  
@Garrett, You would add an event listener to the button.

button.addEventListener(MouseEvent.CLICK, clickhandler);

function clickHandler(e:MouseEvent):void
{
trace("Button: " + e.currentTarget + " clicked!");
}
 worked  Thu Jul 3, 2008 5:05 am  
Can you post a tut on how this would work with a dynamic combo box (populated data from a database)? Or suggest one? Thanks!
 Joe  Tue Jul 8, 2008 12:22 am  
Here's a fix with mini tutorial, if your "getURL" function isn't working:

http://cinemazement.com/blog/?p=8724
 Chris  Wed Jul 9, 2008 2:10 pm  
We're using "navToURL" to send off an HTTP request from Flash movie running as a ".exe" file (not in a browser window). When it does, we need it to NOT launch the web browser and NOT open a web page -- ideally, it would run as an AJAX request in a hidden iFrame, if a browser were to be used. How can I set this up as an invisible pipe between a Flash movie and a remote server?
 mkeefe  Wed Jul 9, 2008 4:09 pm  
@Chris - navigateToURL will not be able to accomplish this. You could use ExternalInterface if your app is wrapped in a browser object.

You could also use XMLSocket to "silently" connect to the server without needing to open a web browser.

Matt
 trickey  Sun Jul 13, 2008 4:57 am  
Hi, please help. I have tried every bit of code I could find in order to get the link working in the same window, but with no joy. It works fine without "_self" in different window, but when I add it nothing happen!! Its killing me!

This is the script I have at the mo, although I have tried many variations:

Portfolio.addEventListener(MouseEvent.CLICK, PortfolioFunction);
function PortfolioFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("portfolio.html");
navigateToURL(request, "_parent");
}


 trickey  Sun Jul 13, 2008 5:17 am  
Sorry, I do currently have "_self" at the end not "_parent".
 Duane  Wed Jul 16, 2008 9:05 pm  
For some reason, my flash cs3 buttons work fine in ie, but will not work in any other browser! The actionscript 3.0 is fine. I don't get it! here is my "about" page button AS, for example:

stop();
about.addEventListener(MouseEvent.CLICK, gotoAboutPage);
function gotoAboutPage(event:MouseEvent):void
{navigateToURL(new URLRequest("http://www.newcenturywebsites.com/about.php"), '_self');}

Anyone have any ideas???
 sam  Mon Jul 21, 2008 8:27 am  
Script works fine when I test the movie in Flash but once uploaded doesnt do anything!
Any ideas would be much appreciated :)
best,
s
 Guest  Wed Jul 23, 2008 11:20 pm  
Mouse Pointer over Link

Is it possible to have the mouse pointer change to the hand to show that it's a link.

Thanks Matt for other tips
 mkeefe  Sun Jul 27, 2008 6:05 pm  
Sorry everyone for the delayed responses.. I have been out of town.

@trickey - Which browser?
@Duane - Make sure you don't have a popup blocker.
@sam - Do you get any runtime errors?
@Guest - Yes, use "clip.buttonMode = true"
 Jennybird  Mon Jul 28, 2008 3:25 pm  
I recently ran into trouble adding the _self parameter on navigateToURL also. In my case it turned out that the problem wasn't in my ActionsScript, but rather my html embed code (html site, with flash navigation).

Setting allowScriptAccess="always" in the containing document, rather than allowScriptAccess="sameDomain" fixed the problem for me. I read on another forum this may fix the issue for those getting a security error. Hope that helps : )
 Jonathan Marcus  Mon Jul 28, 2008 5:13 pm  
I am new to Flash and writing code in general, so any help would be greatly appreciated.

I am trying to have my Flash movie go to a weblink directly from the timeline without the end user having to click a button. Would the code be the same but without the addEventListener or is there a completley different code? For instance, on frame 369 I want the movie to go to www.google.com.

Thanks in advance
 mkeefe  Wed Jul 30, 2008 6:17 am  
@Jonathan - For that task you would simply make a call to "navigateToURL" and leave out the button handler all together.
 Jonathan Marcus  Sat Aug 2, 2008 6:01 am  
mkeefe,

Thank you! I was able to get the flash movie to work just like I wanted to for the freelance gig I was doing. One more question however, if I have 3 flahs movies published in HTML all saved to a location, let's say the C drive, what would I use to direct each movie to the other. Example

Movie 1: Using the Enter_Frame code to take to Movie 2.

Movie 2: Using the Enter_Frame code to take to Movie 3.

Movie 3: Using the Enter_Frame code to go back to Movie 1.

These html movies don't have http:// addresses only local addresses on my hard drive. So the Request to getURL doesn't load the other movies.


Thanks,


Jonathan
 mkeefe  Sat Aug 2, 2008 7:15 am  
@Jonathan - You should be able to use the file:/// protocol, if all the movies are local.
 Elad  Thu Aug 7, 2008 5:50 am  
Hey,
I'm trying to use the code.
When I open the SWF in the flash player- it works.
BUT when I'm trying to do it in IE, or FIREFOX
it says that the SWF is trying to do an unsafe operation (it's like the flashplayer security system)
and if I want to change it..go to -link-
and I can't find where to change it.

plus, it doesn't make sense that I have to change it in every computer just to open a link.

why?

thanks!
 marco Nichola  Mon Aug 11, 2008 8:47 am  
i understand the whole code with link IRL.. but i got my menu in frame1 say.. when i click on the menu which is in frame 1.. i want it to appear in frame2 which is under it.. but i still want frame on to stay where it is.. im geting really confused im using as3.. could you help please ?
 marco Nichola  Mon Aug 11, 2008 8:50 am  
i understand the whole code with link uRL.. but i got my menu in frame1 say.. when i click on the menu which is in frame 1.. i want the url it gets to open to open in frame 2 which is under it.. but i still want frame1 with the menu bar init to stay where it is.. im geting really confused im using as3.. could you help please ? (sorry about the prevous message didnt make sens
 mkeefe  Mon Aug 11, 2008 4:36 pm  
@marco - Not sure if you mean changing frames (in Flash) or in an HTML page. However, the way you change frames in Flash, is to use gotoAndPlay(frame-number) where frame-number is the frame you want to go to.
 matt  Sun Aug 17, 2008 4:01 pm  
can someone enlighten me on how to target a html frame using urlRequest .
here's my code so far.

var request:URLRequest = new URLRequest("main_digital.html");
navigateToURL(request, "contentFrame");

Thanks
 mkeefe  Sun Aug 17, 2008 7:40 pm  
@matt - That should do it.. any warnings or errors?
 MM1182  Tue Aug 19, 2008 10:36 am  
I recently downloaded a flash menu that uses xml. The AS for calling new urls looks like this:

getURL(tD[this._parent.mainMenuPosition].path, "_self");

I'd like the new urls to load in the same browser window but even with the target set to "_self", new urls load in a new browser window. I've also tried "_top" with no success. Does anyone have experience with this kind of code? Is there something else I should be manipulating, like the javascript or the actual xml file? Any help is MUCH appreciated, thanks!!
 marco nichola  Thu Aug 28, 2008 6:54 am  
ok i have created a menu in flash as3... i am putting that flash menu in dreamweaver html.. the html page is split in to two frames, topframe (where the flash menu will be) and mainFrame (where the pages will load up).. basically i got this code:

contactus.addEventListener(MouseEvent.CLICK,callTheFrame);

function callTheFrame(event:MouseEvent):void
{
var request:URLRequest=new URLRequest("test1.html");
navigateToURL(request, mainFrame);
}

as you can see i want the test1.html page to open in the bottom half of my website which is called (mainFrame).. but the code above just keeps opening a new window for me.. can you please help me i am really stuck in this and i just cant manage to do it.. i hope you have understood what i am trying to do..... i dont want the target to be _self, _blank and the rest i want the target to be mainFrame.. help please :)
 mkeefe  Fri Aug 29, 2008 1:58 am  
@marco nichola - try placing the mainFrame in quotes: "mainFrame"
 Mitch  Tue Sep 2, 2008 9:37 pm  
var text:String = "First line of message.n Second line of message";

mailto_mc.addEventListener(MouseEvent.CLICK, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("mailto:some_email@yahoo.com?subject=Check out this new widget!&body="+text)); // Newline isn't passed
}



// This will pass the newline to the body of the email message:
var mailMsg:URLRequest = new URLRequest("mailto:afriend@gmail.com");
var variables:URLVariables = new URLVariables();
variables.subject = "hello";
variables.body = text;
mailMsg.data = variables;
mailMsg.method = URLRequestMethod.GET;
navigateToURL(mailMsg);
 ZionBoy  Wed Sep 10, 2008 5:42 am  
When i use this:

var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank'); // second argument is target
} catch (e:Error) {
trace("Error occurred!");
}


the link opens on a mouseover, how can insert a "on CLick" function?
 mkeefe  Wed Sep 10, 2008 6:02 am  
@ZionBoy - Which mouse event do you have the url opening on? You would want to use, MouseEvent.MOUSE_DOWN .
 ZionBoy  Wed Sep 10, 2008 6:16 am  
I'm still learning AS

Actually, when i roll the mouse on the link, it automatically opens the page, all i want is to click on the link then VOILA...
I guess i need to insert a movieclipname or something but I have no clue how to
 patrick  Wed Sep 17, 2008 9:36 pm  
Can someone please post a working AS3 of a link on a button that loads on the SAME WINDOW please???

_self doesnt work, and i read this whole thread and none seemed to answer it directly...

Thanks in advance!
 Christopher Balli  Sun Sep 21, 2008 1:08 pm  
What makes Adobe or any other program company think we artists / designers / anyone who relys on their products to make a living have the available amount of time it takes to relearn a program entirely everytime they come out with a new version?

Obviousl the developers won this time around with Flash. I can't wait for Flash 10 or 11 to see how things change. Hopefully the artist will have their day. I won't know because I'm about ready to throw up my hands and give this profession up. This is just inconsiderate and stupid.
 imedrano  Thu Sep 25, 2008 1:05 pm  
i AGREE WITH cHRIS
 kael  Fri Oct 3, 2008 11:22 pm  
as patrick said, I had some problem! can some help?
 Hanane  Tue Oct 7, 2008 11:45 am  
I have a few problems.
I cant get change the code for the links. At first i directed the first 3 navigation buttons to our existing site (www.samun.nl). I changed that but the changes do not work for all the buttons. They keep going to the first URL links. And second, i keep getting this:


SecurityError: Error #2148: SWF file http://www.min219000.007sites.com/navbar/navbarsamun.swf cannot access local resource C:Documents and SettingsEigenaarMijn documentenmySamunhome zonder buttonsabout_us.html. Only local-with-filesystem and trusted local SWF files may access local resources.
at global/flash.net::navigateToURL()
at navbarsamun_fla::_master_1/dClick()

And please can you make an example from the code just to see if i am remotely close??
bye bye
Hanane
 Hox  Wed Oct 8, 2008 9:18 am  
getURL type call in AS3 can still be done in one line: (Well two including the import)


import flash.net.*

navigateToURL(new URLRequest("http://site.com"),"_self");
 thomre  Fri Oct 24, 2008 12:19 am  
for those who want to use '_self', try something like this:

<mx:Script>
<![CDATA[

import flash.net.navigateToURL;

private function onClick(event:MouseEvent):void {

var target:Button = event.target as Button;
var url:String = "http://www.google.de";
var request:URLRequest = new URLRequest(url);
try {
if(target.id == "blankB") { navigateToURL(request, '_blank');
} else if(target.id == "selfB") { Security.allowDomain(url);
navigateToURL(request, '_self');
}

} catch(e:Error) {
trace(e.message);
}
}
]]>
</mx:Script>

<mx:VBox>
<mx:Button id="blankB" label="GO new" click="onClick(event)" />
<mx:Button id="selfB" label="GO" click="onClick(event)" />
</mx:VBox>

hope that helps ;-)
 thomre  Fri Oct 24, 2008 12:22 am  
var url:String = "http://www.google.de";
var request:URLRequest = new URLRequest(url);
try{
Security.allowDomain(url);
navigateToURL(request, '_self');
} catch(e:Error) {
trace(e.message)
}
 Acer2004  Tue Nov 11, 2008 1:56 am  
Thanks alot, this article aids me
 glorifiedg  Wed Nov 26, 2008 5:16 am  
I don't understand this article at all. You did a lot of seeming unnecessary things that make it hard to understand the basics of this thing.

I was able to weed out some of it, like, for instance, you don't have to put the url into a variable. But I'm still not clear on why you're using "try" and "catch" blocks.

You said it was to silence error messages if the url isn't found, but if you had mistyped the url, wouldn't you WANT an error message? What's more, wouldn't it be easier to just type the url correctly in the first place?

Are the "try" and "catch" block necessary? or can I just do something simple, like

this.something_mc.navigateToURL(request,"_blank");

Or even better, do you even have to make the "request" variable? I.E.

this.something_mc.navigateToURL("http://site.html","_blank");

Thank you for all your efforts here, but let me give you some advice about teaching. If you want to write a tutorial with all the extras, please start it off with the basics, and then add on the extra things as the tutorial progresses. It will take you longer to write, but you'll spend a whole lot less time answering questions.
 glorifiedg  Wed Nov 26, 2008 5:33 am  
I made it work with as little as this:

var request = new URLRequest("http://www.studio10e.com");
navigateToURL(request,"_blank");

Thanks for the push, though.
 mkeefe  Wed Nov 26, 2008 5:46 am  
@glorifiedg - The try/catch is used to silence the error for the end user. They don't or shouldn't see any errors, especially since they can't modify anything in your code.

This tutorial was not intended to teach AS3 ( others do ) it was intended to answer the question of how to code a getURL (AS2) alternative.

Thank you for commenting, I intend to write more complete articles/tutorials in the future, once I get
some time.
 Jay Kelley  Mon Dec 1, 2008 11:25 am  
Forgive me if this is highjacking a this thread, but my question is "similar" to a URL request.. I would like to open a QUICKTIME player from a button in flash. I have searched high and low for this, but have had no luck.

If you have a suggestion, please idiot-proof it as I am a noob in the worse way.

Thanks in advance

Jay
 Justin  Tue Jan 6, 2009 7:55 am  
FYI, Jay, I believe if you're trying to open a quicktime player, and the video is on the interwebs somewhere, all you'd really need to do is use the "navigateToURL" function to navigate DIRECTLY to the quicktime movie and if the person had quicktime installed on their computer, it would open automatically to play the movie. I don't believe there would be any special commands.... you may want to slap a "_blank" in the code so that the movie opens in it's own window.
 Justin  Tue Jan 6, 2009 7:56 am  
Oh, BTW, thanks for this article. I use Flash all the time, but it's the simple commands I forget when I don't use them enough. I was trying to use a URLLoader to go to a URL :)

 James  Tue Jan 6, 2009 10:53 am  
Thanks for the posts... Very helpful.

Is it possible to open a URL/flash movie in a new layer? If I click on a textlink, I want the specific URL to open in a frame/layer below it.

Any ideas?
 mkeefe  Wed Jan 7, 2009 8:29 am  
@James - You could use "Greybox" to expose a new layer with Flash in it, or did you mean exposing a new layer in a Flash document?
 Moi  Mon Jan 12, 2009 7:27 am  
Is this code OK?? I can't seem to make it work!!

manual.addEventListener(MouseEvent.CLICK, callLink);
function callLink(event:MouseEvent):void {
var url:String = "http://www.wikipedia.org";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
 mkeefe  Mon Jan 12, 2009 8:39 am  
@Moi - That code looks fine here, do you have a MovieClip on the stage with an instance name of "manual"?
 DavidA  Mon Jan 12, 2009 9:40 am  
Hi. thanks in advance for this site, the advice is appreciated.

I am trying to use AS to open a separate email page. I want my guests to be able to send an email to me by just clicking on a button.

Problem is, when I use getURL, a page opens that tries to go to a URL with my email address, which then get the browser to give me the standard error display... I just want a simple email page to open.

Can you give me the complete code to do this?

Thanks,
 Moi  Mon Jan 12, 2009 9:58 am  
Yeah!! well it's a button but I guess that's right! thanks for the quick response by the way XD very aprpreciated!
 mkeefe  Mon Jan 12, 2009 5:48 pm  
@DavidA - For that you would simply use the mailto: protocol. Such as:


navigateToURL(new URLRequest("mailto:user@example.com"), '_blank');


Hope that helps,
Matt
 goose-nick  Wed Jan 14, 2009 10:42 am  
Hi Matt-

I'm using the same mailto: code in a Flex movie, but am having a problem with its behavior in IE6.

navigateToURL(new URLRequest("mailto:user@example.com"), '_blank');

In all browsers (including IE6), the button click results in the appropriate email application being opened. However, in IE6, a new empty browser window is also opened. It contains the mailto: URL in the address bar, and displays an "Action Canceled" message in the browser body. Is this a known issue - or is there some workaround?

Thanks,

Nick
 DavidA  Thu Jan 15, 2009 10:00 am  
Hi Matt,

I tried the code you gave me using Flash CS4 w/ Actionscript 2.0

It didn't seem to work... It could be me.

Can you give me the complete actionscript
from line 1 all the way to the end.

The button name I am using is called:

mail_btn

Thanks again
 mkeefe  Thu Jan 15, 2009 2:13 pm  
@DavidA - Well, if you are using ActionScript 2, that is probably the issue. Here is the complete code:


mail_btn.onRelease = function()
{
getURL("mailto:user@example.com", "_blank");
}


Hope that helps.

Matt
 Shelton  Mon Jan 19, 2009 6:11 am  
mental! i'm new to flash and actionscript, this article has helped me but not sure if it's all correct code...

cheers

Shelton
www.FootballFilms.co.uk
 jatin  Wed Jan 21, 2009 8:26 pm  
how can you give the same actions on multiple buttons? i have appplied it on a frame and it works only on 1 button..
 Stephan  Tue Jan 27, 2009 3:37 am  
I've been searching and searching on the web for a simple tutorial that can show me how to create an email link. I could do with no effort in AS2, but now I'm updating my skills and I have to say, AS3 sucks. Can anyone paste some code on this blog that shows how to create a button that opens Outlook (or whatever) when they click the button?
Any help will really be appreciated.
 mkeefe  Tue Jan 27, 2009 8:08 am  
@Stephan - As mentioned in previous comment, here you go:


navigateToURL(new URLRequest("mailto:user@example.com"), '_blank');


Hope this helps,
Matt
 StretchDongStrong  Wed Jan 28, 2009 2:51 am  
Actionscript 3 doesn't suck. Actionscript 2 sucked.

Actionscript 3 is now a highly functional and extendable object orientated language. If you don't understand it, don't blame the language, blame yourself! Stopping dulling your mind with flash games and get out the AS3 Class Reference doc! Dummies.

 gav  Wed Jan 28, 2009 4:36 am  
as jatin asked:
How do you use this code for more than one button?
I just get a duplicate function error.
 Ferg  Fri Jan 30, 2009 10:32 am  
Hi mkeefe.

Thanks for the page...

I've tried adding your code to a button, but I'm getting the following errors;

'(' expected function callLink:void {

The class or interface 'URLRequest' could not be loaded. var request:URLRequest = new URLRequest(url);

The code I pasted;

myButton.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");

Any ideas?

 Ferg  Fri Jan 30, 2009 10:35 am  
Er...the code I pasted is actually;

myButton.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}

Sorry about that.
 mkeefe  Sat Jan 31, 2009 7:36 am  
@Ferg - Flash should be auto-importing the required classes in this case, however if not, place the following line of code at the top of your document.


import flash.net.*
 Per  Fri Feb 6, 2009 4:40 am  
"I like how it went from a simple code to a huge retared paragraph of programing..."

Why?
 wednesday addams  Sun Feb 22, 2009 4:20 am  
Ok, so I've got all my buttons working perfectly using this code (have used 'google' as an example)...

home_btn.addEventListener(MouseEvent.MOUSE_DOWN,homeHandler);
function homeHandler(event: MouseEvent):void {
navigateToURL(new URLRequest("http://google.com"));
}

However, this constantly opens a new window, so I tried adding the "_self" but now doesnt work at all.
Have played around with it but can't get it right! Could you please show me where to place the "_self", within my code.
Thankyou :)

 Canonsnob  Sun Feb 22, 2009 8:32 am  
I got my links to work finally. But when I updated my web site with new pages and changed my links in the action script in my fla. files they still went to the pages I had originally written the script to. Why would they be ghosting to the old links?
 mkeefe  Sun Feb 22, 2009 9:07 am  
@Per - Not sure really, this is just the "new" way to do things.

@wednesday - Place the "_self" as the second argument of the navigateToURL() function.


navigateToURL(url, "_self");


@Canonsnob - Make sure your server/browser has not cached the OLD SWF. Also, make a change to the SWF visually, such as a date or small shape, to ensure the correct one is being loaded.
 Guest  Mon Mar 2, 2009 6:20 pm  
where do you even get actionscript
 Thomas  Tue Mar 3, 2009 11:38 am  
Sorry, I'm brand new to AS.
Can you please tell me what 'callLink' means in the first line?
 James  Tue Mar 3, 2009 1:04 pm  
Can someone please explain to me why Adobe have made such simple things such a pain in the butt? I thought the idea of releasing next-version code was to make the user experience quicker and easier. After spending many months finally getting to grips with AS2, along comes AS3, and I have to start teaching myself how to use Flash all over again! # sigh #
 mkeefe  Wed Mar 4, 2009 5:04 am  
@Guest - Not 100% I understand your question, but ActionScript is the programming language behind Flash and Flex.

@Thomas - callLink is the function name, which is defined, starting on line 2.

@James - Many aspects of AS3 make things easier and give you more control. So, while it is hard to pick up in the beginning, overall AS3 is better.
 YourWebMaster  Fri Mar 13, 2009 9:52 pm  
@Kevin

here is my implementation of your code. works perfectly. thank you


function button(button,url) {
button.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_self");
}
}

button(home_button,"index.html");
button(photos_button,"photos.html");
button(studio_info_button,"studio-info.html");
button(deal_memo_button,"deal-memo.html");
button(contact_button,"contact.html");
button(map_button,"map.html");
 musgod  Tue Mar 17, 2009 5:24 am  
i have a button that is inside a movie clip. i placed all versions of the working actionscript code in the first frame and the button in the first frame as well, different layer. in the movie the button reacts to the mouse but when i click i get no jump to the link. any suggestions?
 GA55  Wed Mar 18, 2009 3:55 am  
Can anyone tell me how write the code to select just one word out of a paragraph and create a link that would change colors when is clicked??

Thanks
 mkeefe  Wed Mar 18, 2009 5:32 am  
@musgod - Check the name of the function that is called when the link is clicked.

@GA55 - For that task you would use a standard HREF and apply CSS to the text block.
 Chris  Thu Mar 26, 2009 10:49 am  
Hello, I'm having a bit trouble with my buttons, they keep opening new tabs instead of opening in the same one. I've read through the whole page, and a lot of people seem to be having the problem, and some don't, even when using the same code..

Heres the code for one of my buttons:

About.addEventListener(MouseEvent.CLICK, clickAbout);
function clickAbout(event:Event):void {
var request:URLRequest = new URLRequest("about.php");
navigateToURL(request, "_self");
}

Its not my browsers.. any ideas?

Who would have thought putting a link on a button would be so hard? :p
 Chris  Thu Mar 26, 2009 3:33 pm  
Ok, this is strange.. the code I just posted now works..

Not sure what was going on there!
 wilbur5491  Mon Mar 30, 2009 3:40 pm  
I am trying desperately to attach a URL string through xml attached to a button in AS3. I am a newbie. It is part of my video, player which each video is directed to an external URL path when clicked. I hope what I've written makes sense. Can anybody help.

My Code.
function clip_mc_click(evt:MouseEvent):void {
var targetURL:String = e.target.movie_location;
var urlRequest:URLRequest = new URLRequest("movie_location");
navigateToURL(urlRequest);
}
var listurl:String = MenuItem.movie_location.toString();
 mkeefe  Thu Apr 2, 2009 11:12 am  
@blacksmith - Please post your question on the forum as it is beyond the scope of this tutorial.

@wilbur5491 - I have removed your question as it is way beyond the scope of this tutorial. Please post your question on the forum for additional help.

Thanks,
Matt
 das_akeem  Thu Apr 2, 2009 11:03 pm  
thx 4 this thread... as an extension to YourwebMaster's post.. here's my Javascript-button-script:

function jsButton(button, func, val) {
button.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
ExternalInterface.call(func, val);
}
}

jsButton(hey_button, "talk2me", "Hey folks, this works!");

where hey_button is a button from the libary.

talk2me is just a small javascript function in my pageheader:



cheers, das akeem ;)
 das_akeem  Thu Apr 2, 2009 11:07 pm  
uups... this comment script deletes > tags so here's the litte js-function:

function talk2me(txt) {
alert(txt);
}

btw: hey_button is a button from the libary placed and correctly named on the stage ...
 badger  Fri Apr 3, 2009 8:05 am  
@yourwebmaster

"function button(button,url) {
button.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_self");
}
}

button(home_button,"index.html");
button(photos_button,"photos.html");
button(studio_info_button,"studio-info.html");
button(deal_memo_button,"deal-memo.html");
button(contact_button,"contact.html");
button(map_button,"map.html");"

gives me the "access of undefined property" referencing the "home_button" portion of the code. I have the proper instance names placed there, should I be using a different name?
 AncientOutlaw  Wed Apr 8, 2009 9:30 am  
Im trying to figure out how to stop this message once i upload to my site and click (SecurityError: Error #2137: Security sandbox violation: file) Can Someone PLEASE HELP!!
 mkeefe  Wed Apr 8, 2009 6:56 pm  
@AncientOutlaw - Sounds like you are attempting to open a local file in your browser, which is against the web sandbox.
 Navee  Fri Apr 17, 2009 8:20 pm  
@Poster of this subject

Thanks for making sense of the try/catch statement. Adobe's documentation has made my head hurt, but yours is

simple and clear. I just made use of it and I would like to share with other readers an addition to your post by

utlizing mutliple links to urls in best coding practice as possible.

To those having a fit about AS3 over AS2 I completely understand your pain, but AS3 is far better organized,

object-oriented, powerful and the way actionscript should have been since it began. Let's not cry over spilled milk

now. With a little patience and hair pulling you will get through it and truly appreciate the new framework.

Let's make a navigation menu to various websites so that you really get used to the new presence of URLRequest:


1. Open a new AS3 project and create a dynamic textfield on the stage > add text to the field "text button" and

make sure it fits on a single line.


2. With textfield selected on stage, go to properties panel and select embed button and select Uppercase,

Lowercase, Numerals & Punctuations [OK]

3. Give the textfield and instance name of "txt"...then select the dynamic textfield on the stage and convert it to

a movieclip...name it "button" [OK]

4. Now you should have a movieclip on the stage that says text button...okay drag 5 more copies of the button

movieclip to the stage OR copy and paste OR hold down shift+alt(don't let go) and drag out copies.

5. Align and space them horizontal or vertical and give the sequential instancename's "btn1", "btn2",

"btn3"..."btn6"

6. Go back to the main timeline create a new layer for actions and open the actions panel. Type or paste the

following code:
------------ BELOW THIS LINE -------------
//@ the person who looking for color change you have to import ColorTransform
/////////////////////////////////////////////////// | CLASS IMPORTS
import flash.geom.ColorTransform;

/////////////////////////////////////////////////// | Variables for intitial colors (set them!)
var color_clicked:String = "0000FF";

/*
I normally leave 0 index blank so I don't have
to play -1 mind games with myself. I like when 1 really means 1
but if database I have to play by the zero index rules
I create this way during design time for speed, but eventually use XML
*/

/////////////////////////////////////////////////// | Variables
var menu_arr:Array = new Array();
var url_arr:Array = new Array();

// assign labels for text buttons
menu_arr[0] = "";
menu_arr[1] = "Google";
menu_arr[2] = "Yahoo";
menu_arr[3] = "MSN";
menu_arr[4] = "PHP";
menu_arr[5] = "FlashKit";
menu_arr[6] = "YouTube";

// assign urls:
// We could optionally use mutlideminsional array structures...this is more readable
url_arr[0] = "";
url_arr[1] = "http://www.google.com";
url_arr[2] = "http://www.yahoo.com";
url_arr[3] = "http://www.msn.com";
url_arr[4] = "http://www.php.net";
url_arr[5] = "http://www.flashkit.com";
url_arr[6] = "http://www.youtube.com";

// Declared these variables after the array assignments because I want to use the
// length(Number) in the array rather assigning a fixed or known number
var link_num:Number = menu_arr.length;

// This variable will be dynamically assigned in the button event handler
var button_num:Number = new Number();


/////////////////////////////////////////////////// | Initialization Properties
SetButtons();

/*
Using sequential naming conventions helps because you can use a loop
statement and not have to worry about typing addEventListener for every
button and/or textfield in your projects.
Just comment your code to keep track I.e. //Home //About Us //Conact etc.
*/

/*
The fun part: looping. For those who don't understand looping just look at
it and it will come to you soon enough. Normal cases start i=0, but remember I
want 1 to be equal to 1 in the array so i=1. link_num was set above to the length
of the menu_arr. I could have just set it in the loop, but I often use functions
with Numeric returns that dynamically change the value...let's say for a catalog
on another page that I may set values for totally different buttons or links but
still use the SetButtons() method...will show what I mean after you get this down
*/

/////////////////////////////////////////////////// | SetButtons
function SetButtons():void {
for (var i=1; i this["btn"+i].txt.text = menu_arr[i].toString();
this["btn"+i].addEventListener(MouseEvent.CLICK, ButtonClick);
}
}

/*
Here os the heart of the application. I never create URLRequest variables...just create
them inline. I would only create variable if intended for use elsewhere in the code.
I also prefer switch statements for buttons over if statements...easier to read, efficient
and I don't have to keep writing the same live over and over again
I.e. if (evt.currentTarget.name == blah)...else if(evt.currentTarget.name == blah, blah)...etc.
currentTarget.name returns the name of the movieclip object which will be btn1, and so forth.
FYI: In AS2 use switch(this._name)
*/

/////////////////////////////////////////////////// | ButtonClick
function ButtonClick(evt:MouseEvent):void {
switch(evt.currentTarget.name) {

case "btn1":
button_num = 1;
break;

case "btn2":
button_num = 2;
break;

case "btn3":
button_num = 3;
break;

case "btn4":
button_num = 4;
break;

case "btn5":
button_num = 5;
color_clicked = "009900";
break;

case "btn6":
button_num = 6;
color_clicked = "FF0000";
break;
}

// This may hurt your brain. I liked the AS2 way better
// Anyway we set the color of the clicked link at the top. It is just as easy
// to add the variable to one of the cases above and change the value to another color

// Here is your first use of ColorTransform and the variable will be assinged
// to the selected target when clicked
var link_clicked:ColorTransform = evt.currentTarget.transform.colorTransform;

// Now pass in the assigned color value declared at top
link_clicked.color = parseInt("0x"+color_clicked);

// Good lord, now tell the target to transform to the color
evt.currentTarget.transform.colorTransform = link_clicked;

// Yeh, I know but that is how they get down now :(
// Note "btn5" and "btn6" are going to change the color dynamically
// So if you click on 5 or 6 and click on another button the newer color is
// reflected because one of the wise guys changed the value of the variable.
// Just a few ideas on what you could do with changing color since it was asked.
// It sucks but you will get used to it...be patient :)


// Here's that new toy I have been loving thanks to the poster of this article
// Note how we are now using the url_arr created above with web urls, but they
// are arrays so we have to convert them to strings by using the toString() method.
// Optionally we can also use the AS3 casting feature where you write:
// url_arr[button_num] as String;
// Also note that button_num is being assigned by the button you select, and that number
// is used to select the proper index in the url_arr.
try {
navigateToURL(new URLRequest(url_arr[button_num].toString()), "_blank");
} catch (e:Error) {
trace("Error has occured!");
}
}


Hope this helps...Cheers,


Navee
 Navee  Fri Apr 17, 2009 8:31 pm  
Upon preview for some reason the characters in the loop statement within the SetButtons function were fried :( maybe it is character restriction...So let's use pseudo code

It should be like below (you have to convert it to the correct way...unless the poster can straighten it for me) Replace set buttons with this:

function SetButtons():void {
for (var i=1; i (less than) link_num; i++) {
this["btn"+i].txt.text = menu_arr[i].toString();
this["btn"+i].addEventListener(MouseEvent.CLICK, ButtonClick);
}
}

It is important the method is structured properly }else{ it will not work!
 mkeefe  Fri Apr 17, 2009 8:53 pm  
@Navee - Thanks for the code, would you like to see it as a real tutorial on the site? If so, let me know and email me the code. Or I can simply edit this post, your choice.

email: me(at)mkeefe(dot)com
 Thomas  Mon Apr 20, 2009 4:13 am  
i usually use this:

function myButtonFunction(event:MouseEvent) {
navigateToURL(new URLRequest("http://flashgameu.com"););
}

Short and works great..
 Thomas  Mon Apr 20, 2009 4:14 am  
hmm.. i was to quick, it's like this:
navigateToURL(new URLRequest("http://flashgameu.com"));
 Flash Trev  Sun May 3, 2009 9:45 am  
No questions here, just a big thank you for refreshing my memory on how to do this in AS3.

Thanks
 mkeefe  Mon May 4, 2009 6:59 am  
@Flash Trev - No problem, glad it helped you and so many others.
 vsree  Sat May 9, 2009 1:09 am  
Why does not go on net my URL i used AS3
 vsree  Sat May 9, 2009 1:17 am  
please any one help me....

why my URL doesn't work on net i used AS3
i have gaven like this

var request:URLRequest = new URLRequest("www.example.com");
navigateToURL(requestb, "_self");
 mkeefe  Sat May 9, 2009 5:48 am  
@vsree - Looks like you have a misspelling in your variable on the second line, requestb should be request
 vsree  Sat May 9, 2009 6:11 pm  
this is right code

it does not work MKEEFE why...

var request:URLRequest = new URLRequest("www.example.com");
navigateToURL(request, "_self");

 vsree  Sat May 9, 2009 6:16 pm  
When ever i click that button it asked some player security setting......
 Francisc Maria  Sun May 10, 2009 11:03 pm  
Hey mkeefe,
I'm trying to do that, but I'm getting errors like these:
1084: Syntax error: expecting leftparen before colon.
1084: Syntax error: expecting identifier before leftbrace.
1084: Syntax error: expecting rightparen before leftbrace.

I'm putting this code:
movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}

my mc is called
movieClipName and to help I putted his instance like movieClipName«

As you see, I'm not making this up, here is a screen shot to prove what happen:
http://i44.tinypic.com/20ab0uo.jpg

Please help me, this is for a life changing work.
 Guest  Mon May 11, 2009 1:56 am  
Hi....Francisc Maria

copy bellow code paste in your flash actionscript pallate its working fine

import flash.net.*;

movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink(MouseEvent):void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}




movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}



movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {


var url:String = "http://google.com";

var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
 vsree  Mon May 11, 2009 2:00 am  
Hi....Francisc Maria

copy bellow code paste in your flash actionscript pallate its working fine....... I hop it is help for you

import flash.net.*;

movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink(MouseEvent):void {
var url:String = "http://google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
 Francisc Maria  Mon May 11, 2009 10:25 am  
Oh thank god =D
Finally I get this! Ty a lot.
By the way, how can I do a gotoAndStop in AS3.0?
 vsree  Mon May 11, 2009 5:55 pm  
Hi...Francisc Maria

This is your code

movieClipName.gotoAndPlay(frame_number)
 vsree  Tue May 12, 2009 1:40 am  
movieClipName.gotoAndStop(frame_number)
 vsree  Wed May 13, 2009 7:07 pm  
Hi...

I want to connect Mysql database using JSP servlets in AS3.

Please tell me any one.....It is very important and urgent for me
 mkeefe  Mon May 25, 2009 12:12 pm  
@vsree - That is beyond the scope of this tutorial. Please post a question in the forum so others can assist you.
 travisd  Mon Jun 15, 2009 7:39 pm  
Home.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.google.com"),"_self");
trace("");

that's my code, always opens in a new tab. And no, I don't have the links open in new window on firefox. Home is my button name. Please help.
 Sam Laundon  Mon Jun 29, 2009 6:07 am  
Very helpful, thank you. I hope you are still answering questions.
I have a slide show with one invisible button that triggers goto URL. I would like to have this button go to different urls depending on what frame the slide show is on (actually I am using frame labels starting with one, two, three, etc.).

The following works for me for going to the first URL:
one_btn.addEventListener(MouseEvent.CLICK, oneButtonFunction);
function oneButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://sarasotasam.com/blog/wp-content/photos/solstice/217_L.jpg");
navigateToURL(request, "_blank");
}

How would I change the above code if I wanted the URL to change depending on what frame label the move was in.

Thanks in advance for your help - Sam
 mkeefe  Mon Jun 29, 2009 6:16 am  
@Sam - Yes, you would simply use a switch statement with the frame labels, such as:



switch(this.currentLabel)
{
case 'one' :
// call url here
break;
case 'two' :
// call url here
break;

// etc...
}



You would place this in your oneButtonFunction method and then call the correct url.
 Sam Laundon  Mon Jun 29, 2009 9:25 am  
Thanks so much for your quick response. I really appreciate that.
Unfortunately, I really do not know much about Flash and only use it occasionally so I am a bit stumped by where you put the case statements. Would it be too much trouble to ask you to place the case statements in the proper place in this code.? I keep getting all kinds of errors when I try it.

one_btn.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://sarasotasam.com/blog/wp-content/photos/solstice/217_L.jpg");
navigateToURL(request, "_blank");
}

Thanks again - Sam
 mkeefe  Mon Jun 29, 2009 10:32 am  
@Sam - No problem, here is a bit of code that should work.


one_btn.addEventListener(MouseEvent.CLICK, myButtonFunction);

function myButtonFunction(event: MouseEvent)
{
switch(this.currentLabel)
{
case 'one' :
callURL("http://google.com");
break;
case 'two' :
callURL("http://yahoo.com");
break;
}
}

function callURL(url:String)
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
}
 Sam Laundon  Mon Jun 29, 2009 11:53 am  
Thanks so much. You are a Prince! Works perfectly!!

Sam
 Sam Laundon  Mon Jun 29, 2009 12:14 pm  
Actually I spoke a bit too soon. I did not think about the javascript aspect of what I am trying to do. I am using LightBox to open an image over the movie instead of a blank page. How would I implement the code you gave me and add a javascript aspect to it.
This is what I have use before which worked:

onMouseUp = function () {
getURL("javascript:flashLightbox('http://sarasotasam.com/blog/wp-content/photos/solstice/217_L.jpg','Sage Smudging');");

};

Granted this was using Actionscript 2.
I tried putting it here:

navigateToURL(request, "javascript:flashLightbox");

but it did not work.

Thank you - Sam

 mkeefe  Mon Jun 29, 2009 12:19 pm  
@Sam - For that you will want to look into ExternalInterface which is pretty well documented.
 charles  Mon Aug 10, 2009 1:03 am  
I'm having serious problems when I have 4 buttons on a page and trying to link each one to a unique url. I can get away with two working but any more it all goes to pot. Please help.

home_btn.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(event:MouseEvent):void{
navigateToURL(new URLRequest("http://www.kathrynsophie.com"),"_self");
}
about_btn.addEventListener(MouseEvent.CLICK,clickHandler1);
function clickHandler1(event:MouseEvent):void{
navigateToURL(new URLRequest("http://www.kathrynsophie.com"),"_self");
}

gallery_btn.addEventListener(MouseEvent.CLICK,clickHandler2);
function clickHandler2(event:MouseEvent):void{
navigateToURL(new URLRequest("http://www.kathrynsophie.com"),"_self");
}

events_btn.addEventListener(MouseEvent.CLICK,clickHandler3);
function clickHandler3(event:MouseEvent):void{
navigateToURL(new URLRequest("http://www.kathrynsophie.com"),"_self");
}
 SOme Guy  Sun Aug 23, 2009 6:21 am  
PLEASE PLEASE PLEASE ... show me the ID10T who screwed around with adding actions to the buttons in Action Script 3 ... I REAAAALY WANNA FKIN SLAP HIM/HER ...

Come oooon ... you SU-K ... shoot yourself pleeeease!!!
 ricpd  Sun Aug 23, 2009 6:03 pm  
A related question, which I've been scouring your comment section here in hopes of resolving...

My button/urlLinks work fine, but I cannot for the life of me figure out how to also get them to scroll down the destination page to a particular anchor (the fla pages are set up vertically). I've seen it done with Javascript before, but that doesn't work for me either. In fact... I'm having a hard time with anchored frames (within flash cs3 using as3) at all.

help? insight? advice?

here are two sample buttons (two approaches that haven't worked):

padreArch_btn.addEventListener(MouseEvent.CLICK, goPadreArch);
function goPadreArch(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://.../archives.html#/2005to2001")
navigateToURL(request,"javascript:top.scrollTo(0,1000)");
}

// in the above eg, #/2005to2001 is an anchored frame in the first/top horizontal layer of the page , and (0,1000) are the coordinates of the desired vertical anchor/frame at the destination url.//


inbetweenArch_btn.addEventListener(MouseEvent.CLICK, goInbtwnArch);
function goInbtwnArch(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://.../archives.html#/2009to2006")
navigateToURL(request,"javascript:top.scrollTo(#2007)");
}

//above, again, #/2009to2006 is an anchor on the top layer of flash page, in fact in this case it is the first frame of the fla. #2007 is an anchor that is down the page (vertically) that I want the browser to scroll down to upon visitor's arrival at url.//

merci!
 Monica Moreno  Tue Sep 1, 2009 8:43 pm  
Hey guys, thanks a lot!!!! I didn't have a clue about CS3 ActionScrip changes (haven't used flash for a while), but looking at your comments I've been able to do what I wanted (to use a button to open a URL in same window). SO I AM VERY GRATEFUL!!!! HAVE A GOOD DAY!!!!!!
 Jason Kasper  Wed Sep 2, 2009 10:05 am  
Wondering if anyone has any knowledge of how to get buttons on the stage to target labels in a movie clip that resides in the library. it's for a linear slideshow. I need the buttons to either go one label ahead, or one label back.

this is where I'm at so far.....
//button event listeners
prevLabel.addEventListener(MouseEvent.CLICK, navigatePrev);

nextLabel.addEventListener(MouseEvent.CLICK, navigateNext);

function navigatePrev(evt:MouseEvent): void {
slideshow.gotoAndPlay("img1",images);
}

function navigateNext(evt:MouseEvent): void {
slideshow.gotoAndPlay("img9",images);
}

the instance of images (mc in the library) is named "slideshow".

any help or on-line tuts would be appreciated. I haven't been able to find anything!
 chrillo.at  Thu Sep 10, 2009 8:29 am  
Thanks!
 Sean  Thu Oct 1, 2009 10:22 am  
You lie!
 James  Thu Oct 8, 2009 6:08 am  
OK so anyone using google analytics? I'm trying to track the outgoing clicks from my embedded flash object wich is a flip book with multipages, each of them contaian 1 or more buttons that are aimed to navigate to a url. I need to put the code inside flash for various reasons and track each of these individually. So can someone guide me (walk me through) in how I would go about this please?
So far I have thought of adding this to each button....

myButton.addEventListener( MouseEvent.CLICK, onButtonClick );
function onButtonClick( event:Event ):void
{    
  tracker.trackPageview( "/clicked");
}

myButton.addEventListener(MouseEvent.MOUSE_UP,goThere);
function goThere(e:MouseEvent){
    var request:URLRequest = new URLRequest("http://www.myurl.com/");
    navigateToURL(request);
}
 Brad  Thu Nov 12, 2009 4:15 am  
Hi, thanks for the site. 'm getting an error "The class or interface 'URLVariables' could not be loaded.
 mkeefe  Thu Nov 12, 2009 6:50 pm  
@Brad - You need to import the variables class.


import flash.net.URLVariables;
 Ivan Bradley  Tue Nov 17, 2009 7:17 am  
As part of a comprehensive course in Web and Print Publishing, I include a tutorial I wrote on Flash. It includes a simple button link to a URL. Now this was easy in Actionscript 2.0 but I've been rewriting the tutorial for CS4 and am quite frustrated. The following is the AS I placed in a frame.

stop();
btn1.addEventListener(MouseEvent.CLICK, gotoGRC);
function gotoGRC(event:MouseEvent):void{
navigateToURL(new URLRequest("http://www.grc.calpoly.edu/"));
}

The following error message comes up:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at banner_fla::MainTimeline/frame71()
 Andreas  Mon Nov 23, 2009 5:10 am  
Does it make any difference whether the function or addEventListener comes first in the programming?

Thanks for the syntax though!
It works both ways. just curious:)

Andreas
/Denmark
 Markvdb  Mon Dec 7, 2009 6:38 am  
Hi, I have a huge problem!
I'm using Flash cs4, AS3..

This is my code, which u can access at www.ghdesign.org/presspause
ITS ON THE CONTACT PAGE
-----------------------------------------------------------------------------------------


btn_contact.addEventListener(MouseEvent.MOUSE_DOWN, goLink);
email.addEventListener(MouseEvent.MOUSE_DOWN, goEmail);

function goLink(e:MouseEvent):void {
var website:URLRequest = new URLRequest("http://www.presspause.co.za/form");
navigateToURL(website, "_blank");
}

function goEmail(e:MouseEvent):void {
var emailme:URLRequest = new URLRequest("mailto:nicole@presspause.co.za");
navigateToURL(emailme);
}


-----------------------------------------------------------------------------------------
It works fine, but when I use the same script, and change the function names, it doesn't want to anymore?
-----------------------------------------------------------------------------------------

This is what I used on the Related Links - Additional Media/Design Page.



btn_ghdesign.addEventListener(MouseEvent.MOUSE_DOWN, goLink2);
btn_emailme.addEventListener(MouseEvent.MOUSE_DOWN, goEmail2);

function goLink2(e:MouseEvent):void {
var website:URLRequest = new URLRequest("http://www.ghdesign.org");
navigateToURL(website, "_blank");
}

function goEmail2(e:MouseEvent):void {
var emailme:URLRequest = new URLRequest("mailto:info@ghdesign.org");
navigateToURL(emailme);
}


BUT THIS DOESN"T WORK.. AND NEITHER DO any of my little righthand corner ghdesign buttons work..

they are coded using this…


ghdesign.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://www.ghdesign.org";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}


-----------------------------------------------------------------------------------------
… i've tried all of the methods listed on this thread.. but I'm still battling..
CAN YOU HELP? PLEASE
-----------------------------------------------------------------------------------------





Markvdb
 Markvdb  Tue Dec 8, 2009 10:49 pm  
THANKS SO MUCH FOR THE HELP!!

(not)!


this is the solve:

Make sure that you include link in the name and the function name:

link_post.addEventListener(MouseEvent.MOUSE_DOWN, goLinkPost);

function goLinkPost(e:MouseEvent):void {
var website:URLRequest = new URLRequest("http://www.presspause.co.za/post-natal");
navigateToURL(website, "_blank");
}
 MAK  Wed Dec 9, 2009 8:04 am  
Yeah, so sad when professional programmers (Java, Perl, etc.) have to spend hours getting a link to work.

@mkeefe
No offense, but it is funny to see you say how you don't understand why people don't like AS3.

That is like a master mechanic telling a do-it-yourself person: 'gee, I have no idea why you don't find it easy to rebuild a transmission.'

I can just go back to Flash 8 or MX and make a simple Get URL button....unreal how they took the software out of the average user's hands and put it into hard core programmers'. At least leave both options in there, but I suspect, as others have mentioned, it does have to go with getting more money out of people with training and stuff.
 Christian  Sat Dec 19, 2009 7:46 pm  
Thank you for the help with converting to AS3.0's URLRequest.

The code was erroring out for me until I put the Event stuff in like so:

function callLink(event:Event):void {

So if your readers have errors after the button click, that might fix them.

(and yes, I miss the 1-line-of-code days as well)
 TL  Thu Dec 24, 2009 6:14 am  
I've got all this and have used it to work easily... however, if you have to pass paramters to the webpage loaded then it will not work on IE. I've tried directly additng it to the address launched (e.g. http://www.google.com?someparam=why_does_ie_hate_me), and also using the whole url variables and nothing. IE always strips that stuff out, while it works perfectly well in Firefox. Unfortunately I have to work in IE, so this is a big issue. Anyone have any thoughts on this.
 Meenu  Tue Dec 29, 2009 11:03 pm  
mybutton. addEventListener(MouseEvent.CLICK, myButtonFunctionCZ);
function myButtonFunctionCZ(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://www.umayal.com.my/index/");
navigateToURL(request);

}


Please help me.....i have been cracking my head since 3days....unable to link to tht particular site it shows :

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at UMAYAL_INTRO_new_fla::MainTimeline/frame550()
 mkeefe  Wed Jan 6, 2010 12:29 pm  
@Meenu - Make sure your "mybutton" is properly on the Stage and that is the correct instance name.

@TL - You want to use URLVariables and make sure you set the method to "GET" and ensure the line is properly formatted.

Is ActionScript 3 Difficult for no reason?
Things did get complicated in AS3 to some extent but overall the additions far outweigh the steep learning curve. When a company (such as Adobe) tries to implement more complex APIs and libraries things are bound to change. Now I don't know why exactly they made certain choices but I think in the end if you learn it you will be fine.
 Beso  Sat Jan 9, 2010 7:01 pm  
all i gotta say is PRO!

thanks alot for the tips, getting back to flash from flash mx to cs4 is a HUGE gap i missed on and this was one of them i read alot of tutorials but NONE of them told you where to put the command _self


Again
THANK YOU!
 scott  Fri Jan 29, 2010 3:28 am  
im getting

1021: Duplicate function definition.
 mkeefe  Sat Jan 30, 2010 5:58 am  
@scott - Verify you didn't type or copy/paste the function more than once. If you do need multiple copies then make sure the function name is changed each time, there can't be more than one, as you now can see.
 Guest  Mon Feb 22, 2010 5:43 pm  
my code looks like this and i keep getting an undefined property error for my button which is properly on the stage

btn_shopaholicmama.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://shopaholicmama.com");
navigateToURL(request);
}
 Guest  Mon Feb 22, 2010 7:08 pm  
guest above continued

I am trying to make the swf movie a link when it is on the webpage. i made a button that is the entire background of the graphic. is there an easier way to do this?
 Rajkumar  Thu Feb 25, 2010 9:41 pm  
Hi !! I use navigateToURL(request,"_self"); to call a servlet which downloads a excel. The first time i click the button the excel is donloaded. But the next time i click the button the excel does not open. The servlet is not called. Can anyone help me out.
 Farhan  Fri Feb 26, 2010 10:01 am  
hi..
i am making demo website and i want to send querysting fla file to html(javascript) with out using (http://)protocall how can do this plz help me??

btn1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {

var request:URLRequest = new URLRequest("Sindh.htm?selMain=1");
navigateToURL(request,"_self");
}
its not work .
 mkeefe  Tue Mar 2, 2010 5:44 am  
@Farhan - You need to use URLVariables in order to send query string parameters in Actionscript 3.
 Salaka  Sat Mar 13, 2010 2:04 am  
Dears,

Can i add with the request fixed window size

{var request:URLRequest=new URLRequest("advanc_course.htm");
navigateToURL(request,"_blank","h=100","w=200");

it's dummy code but i want to know is it possible or no as am not AS3 expert.

Thanks
 mkeefe  Mon Mar 15, 2010 5:04 am  
@Salaka - No, you would have to use Javascript and ExternalInterface in order to open custom windows.
 gvbaker  Wed Mar 17, 2010 10:46 am  
I struggled with the above shenanigans until I did not export my buttons for actionScript. Seems to work now.
 ry  Sun Mar 28, 2010 5:56 am  
I am getting confused with this. I want a URL link on a button which is part of a movie clip being called to the stage.
 David  Tue Apr 6, 2010 4:14 pm  
Can someone please help me?
I have several buttons on the web page I am developing all of which I want to open in current window - I am using AC3.
I can get them to open in a new window, no problem, but when I try adding "-self" or "_parent" to the script nothing happens when clicking on the buttons.
Here is the script that I am using.

item1_Btn.addEventListener(MouseEvent.MOUSE_DOWN, item1Handler);
function item1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("brushes.html_"));
}

Thanks in advance.
David
 David  Tue Apr 6, 2010 4:25 pm  
Re: above......sorry I typed incorrectly....here is the script again.....

item1_Btn.addEventListener(MouseEvent.MOUSE_DOWN, item1Handler);
function item1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("brushes.html"));
}
item2_Btn.addEventListener(MouseEvent.MOUSE_DOWN, item2Handler);
function item2Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("combs.html"));
}

....and so on up to item10.....

Cheers
David
 ddloada  Thu Apr 15, 2010 8:09 pm  
@mkeefe

hi,there i am trying to get a flash movie to load a page after the movie has ended, i have the stop(); command for when the index.html page loads the movie should sit still until i click a button which play(); the movie, then should call the page when movie finishes, but it does not and continues to the page i want to load when using _"self" target.

this is the code im using for the link,

navigateToURL(new URLRequest("http://www.mysite.com/maintenance.php"), "_self");

can u help me with this all i want is for when i go to the URL of mysite the page should sit still until i call the next page which is when the movie ends, also want it in the same window, right now it bypasses my flash movie completely going to the next page.
 Nope  Fri Apr 16, 2010 9:22 am  
Hi,

I am trying to create a link from my flash website in new web browser. I am using Adobe Flash cs, it has action scrip 3 but I am using 1.0 and 2.0
I tried the sourcecode above :
getURL("urltoload", "target");
and I get an error : statement must appear on/onclipevent handler.

Thanks in advance for you help
 Mikersson  Sun Apr 18, 2010 6:03 pm  
Hello, IM trying to open a link after I click on a logo.
Now the AS do not works. I want to link the home page index.html in same window.

Could you tll mw how to do that?
Thank you
 mkeefe  Wed Apr 21, 2010 1:48 pm  
@ddloada & @Mikersson - Ensure your target is set to "_self".
 prijatel-MKD  Fri Apr 23, 2010 2:00 pm  
I'm using the next code for url request in as3, it works fine for me.

For opening URL, first after importing object into the stage is converting the item into "Button", than defining the 4 states of the button (Up / for invisible button inserting an empty keyframe; over; down; hit) and the next code.
For one button on the stage:

//Code:
Btn1.addEventListener(MouseEvent.MOUSE_DOWN, myBtn1Handler);
function myBtn1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.UrlDomen/Btn1page.php"), "_self");
}
//End code.

For two + buttons (next code is for two) inserting them in the same layer in time line and applying the AS code to the same layer with the buttons. When I put the buttons in different layers, actions script goes into empty layer on top of every layers, instance names must be writen corectly.

//Code:
Btn1.addEventListener(MouseEvent.MOUSE_DOWN, myBtn1Handler);
Btn2.addEventListener(MouseEvent.MOUSE_DOWN, myBtn2Handler);
function myBtn1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.UrlDomen/Btn1page.php"), "_self");
}
function myBtn2Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.UrlDomen/Btn2page.htm"), "_blank");
}
//Code ends.

For email button, the same code, just for url=mailto:adress.

//Code:
EmailBtn1.addEventListener(MouseEvent.MOUSE_DOWN, myEmailBtn1Handler);
function myEmailBtn1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest("mailto:Email@domen.com"), "_blank");
}
//Code ends.

"_self" for opening into same tab/window; "_blank" for new tab/window depending on seting in the user browser.

Try it, hope will help.
 ddloada   Tue Apr 27, 2010 8:39 pm  
@mkeefe - Thanks for the reply, this is what is happening
when my target is set to "_self", in Firefox, Safari, IE and Chrome browsers mysite.com when loaded skips to the home page which i have as the body of the site without me telling it to do so.

what I want is after i go to mysite.com that page which is my index page should sit until i click a button that plays the flash movie, then when that movie finishies the home page is called which is the body of the site.

stop();

bX.addEventListener(MouseEvent.CLICK, playAnimation);
function playAnimation(event:MouseEvent):void
{
play();
}

navigateToURL(new URLRequest("http://www.mysite.com/home.php"), "_self");

that was just some of the code, there are other code like rollovers, glows and tweens which i left out, these are the more important parts that have to do with how the page reacts, just to give you an idea.
Everything works great except the index page dont stay,just skips to the home Page so i cant even play the movie.

Help Please.
 mua  Fri Apr 30, 2010 9:34 am  
I am trying to make my last frame go to the URL,

I remember doing this on AS2 by using
on load
getURL("urltoload", "target");

command, however it doesn't work that way anymore on AS3.. can someone please help me.. I see everyone posted comments on how to get URL on mouse event, but how to make it get URL onload..Thanks
 mkeefe  Fri Apr 30, 2010 10:18 am  
@mua - Here is the code for that:


navigateToURL(new URLRequest("http://google.com"));


Now just place that code on the last frame.
 mua  Fri Apr 30, 2010 10:51 am  
Oh no that is no good senior... i have tried that.. I am using CS4 AS3
 mkeefe  Fri Apr 30, 2010 5:53 pm  
@mua - I will need to know more about the issue then because that code I post IS how you call a link ActionScript 3.
 ddloada  Sun May 2, 2010 2:36 pm  
when the Target is set to "_self" in the browsers the Page loads but skips to the link, I have a Flash movie and a button which plays the movie which at the end of the movie the link is called.

can anyone help me please, this is the code I am using -

navigateToURL(new URLRequest("http://www.mysite.com/maintenance.php"), "_self");

The flash movie and button are on mysite.com page and i want to load the maintenance.php page when movie is finished on the same page.
 ddloada  Sun May 2, 2010 6:40 pm  
I figured it out if anyone was wondering all you have to do is add a keyframe at the end of the movie and paste the code there, it works perfectly now

navigateToURL(new URLRequest("http://www.mysite.com/maintenance.php"), "_self");
 Al swaidi  Mon May 10, 2010 4:52 am  
Hi everyone ,

I want to link different SWF files by clicking the button , moreover, I'm using script 3.

In script 1 and 2 i was using

on (press){loadMovieNum("home page.swf",0)}

WHAT CAN I USE IN SCRIPT 3 ..

PLEASE HELP !
 rorose  Sun May 23, 2010 3:23 pm  
The forward slashes in the website address cause the rest of it to grey out like a comment. How to fix this?



function gotoSoccerSite(evtObject:MouseEvent):void {
var soccerURL:URLRequest = new URLRequest (“http://www.usyouthsoccer.org/”);
navigateToURL(soccerURL);
}
function gotoSoftballSite(evtObject:MouseEvent):void {
var softballURL:URLRequest = new URLRequest (“http://www.softball.org/”);
navigateToURL(softballURL);
}
function gotoAllianceSite(evtObject:MouseEvent):void {
var allianceURL:URLRequest = new URLRequest (“http://www.nays.org/”);
navigateToURL(allianceURL);
}
soccer_btn.addEventListener(MouseEvent.CLICK, gotoSoccerSite);

 Rajkumar  Sun May 23, 2010 11:36 pm  
Thanks dude..
 mkeefe  Mon May 24, 2010 5:03 am  
@rorose - Make sure your quotes (") are not specialized, just standard quotes. It looks like in your sample you are using quotes from a Word Processor.
 jan  Wed May 26, 2010 10:40 pm  
Hi can you help me i´ve got my navigate flash menu on my HTML site i´d like to selected button on current page.. Iknow that code for html is ....navigate.swf?page=1 but i dont know what code is in Flash
 mkeefe  Fri May 28, 2010 8:00 am  
@jan - You would want to use "loaderInfo.parameters" once the swf is loaded. Such as:


if(loaderInfo.parameters != null)
{
trace("The page is: " + loaderInfo.parameters.page);
}
 JimE  Fri Jun 4, 2010 11:11 am  
New to ActionScript 3, trying to make simple button to go to specific URL, my code only opens my default browser to it's default page, not to the specified link. What am I doing wrong. Thanks.

catalogBtn.addEventListener(MouseEvent.CLICK, discover);
function discover(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.fmmafco.com"));
}
 onion  Tue Jun 8, 2010 6:41 am  
Thanks for posting this article, I'm new to AS3 and quite dismayed that you suddenly now have to write a lot more code! But this helps, thanks.
 Saeed  Tue Jun 8, 2010 10:29 am  
in flash.swf

i point the heder to myikon.webatu.com

but it didnt take me there when i write

www.myikon.webatu.com
 Roger Andreeta  Sat Jul 10, 2010 5:12 am  
Thank you for help me.
I finished my job when I read the first tip.
Roger from Brazil.
 Peter  Tue Aug 10, 2010 9:50 pm  
Given how relatively simple it used to be to create a working button using AS2, and the string of comments here, it's not exactly a feather in Adobe's cap to have made it this convoluted in the 'new improved' version.
 JEN  Fri Aug 20, 2010 7:06 am  
I keep getting this error:

1120: Access of undefined property movieClipName.
 Jeff  Mon Aug 23, 2010 11:57 am  
How would the code look if I wanted to have more than 2 getURL's?

Would it be like this? cause I keep getting an error.

movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}

movieClipName2.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
 tgrdesigns  Wed Sep 8, 2010 11:36 am  
If you are looking to make a button with a link to the same page..

this is your code
_____________________


function gotomySite(event:MouseEvent):void {
navigateToURL(new URLRequest("links.htm"),"_self");
}
home_btn.addEventListener(MouseEvent.CLICK, gotomySite);
____________________________

Where home_btn is the name of your button. I would like to note, you dont have to use "httP://" to link, where links.htm is the page you are linking to in your site, the "_self" can be the name of your frame etc. "_self" refers to the window you have open, you can use "
_parent", "_blank" etc. I hope this helped, took me like 3 hours to figure out how to do this, and i have been programming in as for years now... ty as3 for making my life harder.. guh. :(
 Venom15  Fri Sep 10, 2010 8:50 am  
Hi All,
I have imported a FLV into an FLA and I wanted to load a new url (HTML page) after the movie has finished playing. Can you tell me what code should I put to make this happen?

Regards,
Venky
 pitipoance  Tue Sep 14, 2010 12:28 am  
thx for posting! very useful
 kaissun  Wed Sep 22, 2010 5:55 am  
but if i want to have a link button to another page in my projet how can i do ???
 AJ  Mon Sep 27, 2010 8:25 pm  
Thank you very much for posting this code. I'm new to AS3 and only now breaking code up so I can understand how to fix it. Yours was awesome.
 PJ  Tue Sep 28, 2010 3:04 pm  
I using flash Cs4. I want link exe file in flash. so I need how to do. I using Action Script 2.0. Thanks
 KP  Wed Oct 20, 2010 5:52 am  
Hi,
I was wondering if someone could please help me with some actionscript...
I have a button that has a movie clip in both "down" and "over". Basically I want an animation to play when I hover over my button and a second animation to play when I click it, then I want to open an HTML page within the same window.
Everything works fine except when I click the button, the animation doesn't show up it just goes straight to the HTML page. How do I make it so that the entire "down" animation plays before going to the HTML page?

Thank you!
 Ryan  Thu Nov 4, 2010 11:00 am  
I have a email form that when you submit your email it will navigate to a new page with out opening a new tab, I've tried '_self' as the target but it doesn't go any where, however it works just fine if i use '_blank'

Here is my code:

import flash.events.*;

import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;


submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

stop();

function ValidateAndSend(event:MouseEvent):void
{

//validate form fields
if(!email_txt.length)
{
status_txt.text = "Please enter an email address";
}
else if(!validateEmail(email_txt.text))
{
status_txt.text = "Please enter a VALID email address";
}
else
{
status_txt.text = "Thanks, your email has been sent!";

var url:String = "emailConfirmation.html?email="+escape(email_txt.text);
var request:URLRequest = new URLRequest(url);
navigateToURL(request, '_self');


}

}
 mkeefe  Tue Nov 9, 2010 4:44 am  
@Ryan - I would simply remove the target, or set it to "" and then Flash Player should default to the same tab or window.
 bart de boer  Wed Dec 1, 2010 2:24 am  
This could be written shorter by the ones complaining about the length of the code:

navigateToURL(new URLRequest(http://site.com), '_blank');

Or with a simple function:

navigate("http://www.site.com","_zelf");

private function navigate(file:String,target:String):void {
var url:String = file;
var urlReq:URLRequest = new URLRequest(url);
try{
navigateToURL(urlReq,target);
}
catch(e:Error){
trace(e);
}
}

The pros of a function including a try and a catch is the code will continue when the page can't be found. It's user-friendly to place pop up a screen that the links it outdated.
 John Clarkson  Wed Dec 1, 2010 3:30 pm  
Hi I used the GET URL command with the _self or _parent, and neither prevent my opening page from then opening a new window if you click one of the flash buttons. Once of course you're inside the new window it works fine. That's really weird. This is the script I used. Like I said I also used _self and it worked the same. I don't understand. I thought that _self would make sure that it opened in the same window. When I changed it to _parent it made difference. Really weird. _top doesn't work at all. Running out of ideas guys, so any help before I go completely mad would be great! I'm not very experienced at this so if it sounds as if I'm stupid, well, when it comes to actionscripts I am. Cheers.

news.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/",target=_parent);
}
about_us.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/About_us.html",target=_parent);
}
fanzone.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/Fanzone.html",target=_parent);
}
shop.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/shop.html",target=_parent);
}
links.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/links.html",target=_parent);
}
email.onRelease=function() {
getURL("http://www.bornefromabove.co.uk/email.html",target=_parent);
}
 Lee  Mon Dec 6, 2010 6:53 am  
Hi very sorry to bother you, but i'm having the biggest problem.

I'm using external pages using AS 3.0, and I have a button in my library which is in my index page. Now I'm working from another AS file called 'page_books'.

I need to give a button within a movieClip a URL link but from my 'page_books' .as file. So far I have this code:

import flash.net.URLRequest;
import flash.net.navigateToURL;

btn_books_1.addEventListener(MouseEvent.CLICK, gotoSite);


function gotoSite(event:MouseEvent):void{

var myURL:URLRequest = new URLRequest("http://www.amazon.com");
navigateToURL(myURL,"_blank");
}

I have one error message which says:

C:UsersLeeDesktopFlash Website - OOProgrammingsite_classespage_books.as, Line 76 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.

I have no clue how to fix this and i've been trying for so long. Can anyone give me a hand by any chance? Thanks a lot.
 mkeefe  Mon Dec 6, 2010 1:33 pm  
@Lee - Is btn_books_1 a movieclip instance or a custom class? It seems if its a custom class then it needs to extend MovieClip or Sprite. The other option is to cast the object as a MovieClip, such as:



MovieClip(this['btn_books_1']).addEventListener();



Hope that helps.
 Lee  Tue Dec 7, 2010 2:28 am  
Hi thanks so much for the fast reply.

btn_books_1 is a button which resides within a movieClip in the index.fla file.

As I have all my page classes externally linked I have to create a link for a button which is in the index.fla file. I've gone into the properties within the btn_books_1 and changed to 'Export for ActionScript' and then gave it the same name btn_books_1.

Now the base class is: flash.display.SimpleButton

Sometimes I think I understand AS and then it doesnt work lol Very annoying.

Should I put the btn inside of a movieClip?
 mkeefe  Tue Dec 7, 2010 6:13 am  
@Lee - That is a strange one for sure. Can you check if "Declare Stage Instances" is checked in the Publish Settings? If not, check that.

Whats happening is ActionScript isn't seeing the movieclip on your stage. I assume you created a document class and are referencing your instances in there? If not be sure you have a Document Class, assigned in the Properties panel when you click on a blank portion of the stage.
 Jens Herskind  Mon Jan 17, 2011 1:36 am  
i use this:

btn_beretninger.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://politiken.dk/indland/fakta_indland/ECE489168/faldne-danske-soldater-i-afghanistan/");
navigateToURL(request);
}

And it works ok inside flash (test movie): it opens the site i link to.
BUT!!
it does NOT work when i test the .swf in a browser. It says:"Flash Plapyer has stopped an unsafe.." etc ..

?!
 Jens Herskid  Mon Jan 17, 2011 2:14 am  
i use this - cont.

sorry: it works!! (just didn't when i opened it locally)

Have to agree though -- a simple routine has become a complex operation involving navigateToURL, movieclips, voids and errors ..Yikes!!
 Jacob  Fri Jan 28, 2011 8:00 am  
Hello all!

I found this great AS3 mac-style dock I wanna use.

Download it here: http://poontang.dk/as3dock.rar

Now, how do I make each icon link to a html - and set the target for it?

Please help - I am VERY new to AS3 :o/
 Jacob   Fri Jan 28, 2011 8:21 am  
- Actually, Jens Herskind's script above my posts works fine for me!
But I can't set the target for it?
 medical assistant  Wed Feb 2, 2011 1:19 am  
I haven't done anything on flash for years. i stopped working on flash when the latest version was 6 or 7. Now i'm in need of creating a button which takes url from html and create a link. when it is clicked it goes to that url. any idea how to do that?
 jigar  Mon Feb 7, 2011 2:55 am  
Where to write the above code for the link in the actionscript 3 b'coz i can not get any event enable in my adobe flash cs4
 mkeefe  Mon Feb 7, 2011 3:03 am  
@jigar - I am not sure I follow.. are you asking how to change the URL or attach the mouse click event?
 Helsic  Thu Feb 17, 2011 5:45 am  
Ok, this one works for me:

myButton.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http://flashgameu.com");
navigateToURL(request);
}

thanks!
 James  Fri Mar 11, 2011 9:15 am  
And all this extra code and learning it it better because? AS2 is for designers, AS3 is for developers. If ADOBE ever drop AS2 completely, they really will be losing a lot of customers for their product, and a lot of designers will be out of business. As for learning AS3 - from what I've read, many a designer has tried hard, but failed.
 Brian Davis  Tue Mar 15, 2011 7:39 am  
re: your misleading post:

this blog post makes it look like AS3 requires sooo much more code. to compare apples to apples. the AS3 would look more like this

navigateToURL(new URLRequest("urltoload"), "_blank");

or alternatively you could change the AS2 to declare variables for every string passed, and provide error checking.
 mkeefe  Tue Mar 15, 2011 7:59 am  
There isn't all that much more code required. Most of it is for "good programming practices". AS3 has been around for years now, its time to adapt and start enjoying the benefits available to ONLY AS3.
 Birdie Golden  Sun Mar 20, 2011 4:34 pm  
Guys - remember, if you're testing this locally, your url is going to go to your NON-Updated website.

Thus always opening in an "_blank" window.

Upload, and then try.
 Loukas  Thu Apr 7, 2011 4:06 am  
Hello everyone,

I am trying to add an url link to a DAE model using Actionscript 3.0 in Flash Builder. However, the code above for some reason doesn't work. Any ideas or suggestions how I can make it work? It is an AR project and the idea is that when the marker is presented in front of the camera, my DAE model appears and if the user clicks on it then the web browser starts and it takes you to a specified (in Actionscript) website.

Any help is much appreciated as I am stuck!

Many thanks,

Loukas
 Ketchup  Sun Apr 10, 2011 7:28 pm  
Hi.
Thanks everyone for you're posts here. I agree AS2 is much easier for designers - but I'm determined to learn AS3 - I've FINALLY got my link to the URL working. Only one thing thats not esential but I would like - is that when the frame that has the action applied to it is visable - the cursor stays as an arrow - and doesn't change to a hand that would indicate that there is an active link. Is there anyway of adding this?

Thanks!
 mkeefe  Tue Apr 12, 2011 7:10 am  
@Ketchup - You can use buttonMode = false;
 Ketchup  Tue Apr 12, 2011 4:53 pm  
Thanks!
 Plesanz  Wed Apr 13, 2011 8:21 am  
Ok here is the solution to navigateToURL (req, "_self")
just add a little script in html where the swf file is located, just added ..
param name = "allowScriptAccess" value = "always".

Hope this is useful or directly go to this site http://kb2.adobe.com/cps/000/50c1cf38.html
 The Toast Entperise  Thu Apr 28, 2011 7:07 am  
Hey, I Urgently need help with my coding :( I only have THREE buttons on the page-
And after sitting for THREE hours trying to get this Actionscript THREE to work (exporting from Flash CS4)
It's not giving me any errors anymore, but it's simply just not linking to any of the URLS'.
Please. someone. he(lll)p.


btn_wildlife.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.gmm-grp.com/worpress/"));
}
btn_tensile.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.gmm-shade.com/"));
}
btn_logistics.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
navigateToURL(new URLRequest("construction.html/"));
}
 synian  Mon Jun 6, 2011 3:00 am  
I use flash only to make some fancy menu's and sometimes for a few GFX on the website.

I finally upgraded my old flash program to the new one, and I must say... I already hate AS3 with every bone in my body.

it's like someone within Adobe thought... let's make AS3 so people will hate making thing in flash.

WHY would they change all this....
AS2 - ya make a bunch of buttons, and give each button a function...
AS3 - ya make a bunch of buttons, and give each button a name. then write 3 to 5 lines of text (for EACH button) somewhere else,.. and all the handeling need seperate names, because it's a different kind of action.... (example: mouseDownHandler1, mouseDownHandler2, mouseDownHandler3)

NO... It's not a different kind of action... it's the same action... open an URL in a window/frame. the only difference is... the URL (for each button.)

I've noticed that a simpel - stop (); - action doesn't even always work as you want to...

I love the 3D option (didn't have that in previous verion I had).... but don't know if the trouble to put in a simpel button action.... is worth the 3D look...
 Emily  Tue Aug 16, 2011 2:12 pm  
Anyone know if it is possible to run the url, but never actually open a window of any kind? I'm trying to run a URL to increment a poll in a database and I don't actually want to open a page in a browser...

Thanks!
 mkeefe  Wed Aug 17, 2011 7:01 am  
@Emily - For that you would want to use URLRequest and URLLoader. Then just silently call the url.
 Leon  Fri Aug 26, 2011 3:46 am  
i have a question:

how do i use a actionscript function in a mode that when i click on a flash button it access a web page but does not go to that web page, somewhat like a transparent inexistent page and il does nothing...

Thanks .... p.s. sorry for my english
 Leon  Fri Aug 26, 2011 4:40 am  
later:

@Emily:

button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);

function fl_ClickToGoToWebPage_3(event:MouseEvent):void
{
var url:String = "test.php";
var request:URLRequest = new URLRequest(url);
sendToURL(request);
// navigateToURL(request);
var loader:URLLoader = new URLLoader();
loader.load(request);

}
 mkeefe  Fri Aug 26, 2011 12:33 pm  
@Leon:

For that you would want to use URLRequest and URLLoader. Then just silently call the url.
 medical  Wed Sep 28, 2011 7:07 am  
this is right code, it works fine now
 Leon  Sun Oct 2, 2011 7:08 am  
@mkeefe: could you make an example? thank you
 stronyflash  Wed Oct 19, 2011 3:42 pm  
@Leon It doesn't work
 vincenzo  Mon Oct 31, 2011 4:18 am  
wtf! AS2 code was short and efficient, now I must write a lot to obtain this easy feature...Adobe shit!
Javascript is much better for web application. I think AS2 is even better way for my purposes.
 vito  Sat Nov 19, 2011 2:37 pm  
if you don't download flashplayer by adobe... there are errors.
 Mike  Tue Jan 3, 2012 4:36 am  
I've tried adding a url to my button, thing is it won't work maybe because i added a rollover function that changes picture whenever i roll over the button and i have those up down hit over options ... Do i need to add something more to the code and furthermore do i need to do something on the HIT highlight of the button so the url works ? Thanks in advance
Add a comment
The ability to add new comments has been disabled in this archived version.

Loading
Main | Tutorials | Articles