navigateToUrl AS3 is not opening a web browser - actionscript-3

I have a textField on my stage named 'adBuy', which when clicked I want to open up my browser with the defined in URL request. However when I click on the 'adBuy' textField on my SWF it opens Coda, the piece of software I'm using to write this small piece of code?
I am puzzled. Here is my code:
adBuy.defaultTextFormat = adFormat;
adBuy.textColor = 0xFF65CB;
adBuy.x = 640;
adBuy.y = 455;
adBuy.text = "Buy Now";
parent.addChild(adBuy);
adBuy.addEventListener(MouseEvent.CLICK, buyAdvert);
var request:URLRequest = new URLRequest("http://www.google.co.uk");
function buyAdvert(event:MouseEvent):void {
navigateToURL(request, "_blank");
trace("link clicked");
}
Is there an error in my code, or is this a common problem for which there is an answer?

Sorry, I have solved my problem.
It appears the reason it was not opening a web browser with the URL it because I was running the SWF through 'Test Movie' in Flash. This appears to have been stopping the code working.
It did however work fine when I ran it in Flash Player.

Related

Is there a way to make clicking a button in Adobe Flash open multiple hyperlinks?

Simply put, is there a way to make clicking a button object in Flash Actionscript 3.0 open two hyperlinks in a browser? I've tried messing with the Actionscript and adding multiple functions, to no avail.
Use two different window strings:
var url:URLRequest = new URLRequest("http://stackoverflow.com/questions/35561823/is-there-a-way-to-make-clicking-a-button-in-adobe-flash-open-multiple-hyperlinks");
navigateToURL(url, "_blank");
var url:URLRequest = new URLRequest("http://www.stackoverflow.com");
navigateToURL(url, "_blank2");
Note:
For local content (via file://) running in a browser, navigateToURL will not work unless your html/swf is in the local-trusted security sandbox.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#navigateToURL()

In chrome, swf can not run

swf code, and file name is test.swf:
function test() {
trace('this is a test');
}
test();
I visit it by http://localhost/test.swf
but I get nothing in window.
chrome version: 46.0.2490.86 m
chrome:plugin
Adobe Flash Player - version: 19.0.0.245
Shockwave Flash 19.0 r0
It would seem you are unclear on what trace does in ActionScript.
While some languages have a print or echo type command, AS does not.
trace() is for debugging, to send a message to the output panel when your code is running in the debug flash player.
So with the code you've shown, the expected result is a blank screen as the code doesn't do anything that affects the screen.
If you want to put text on the screen, you'd have to do the following:
function test():void {
var tf:TextField = new TextField();
tf.text = "this is a test";
addChild(tf);
}
test();
If you want to use trace statements in the browser for debugging, you'll have to install the flash debug player for your browser.
Once installed, you can start a remote debug session in FlashPro.
Please follow this tutorial for making textFields to hold visible text within your SWF.
Textfield tutorial
Alternatively if you want something like a browser alert/pop-up then try
Javascript Alert from AS3 tutorial

How make with AS3 downloading MP3 files in the background mode and plays it?

I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html but do not know how to do it? Prompt what code and how to use it properly?
You can directly load a Sound object with an URLRequest instead of using a separate Loader or URLLoader. A code could look like this:
// this code should reside in a function somewhere
var request:URLRequest = new URLRequest("http://your.site.com/your.mp3");
var sound:Sound = new Sound(request;
sound.addEventListener(Event.COMPLETE, completeHandler);
// this function should be at top level anyway
private function completeHandler(event:Event):void
{
var loadedMP3:Sound = Sound(event.target);
if (loadedMP3) loadedMP3.play();
}
Extra error handling is up to you.

How to auto load URL through SWF banner in the background?

I am new here just signed up and I did not find information on how to classify this topic on specific section.
I am using adobe flash professional to create a small banner to auto load one of my own URL for analytics. Is this possible? I found one solution on another user's topic which was (AS 3):
var req:URLRequest("http://your_request");
var loader:URLLoader = new URLLoader ();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(req);
private function onLoadComplete(ev:Event):void
{
var result:String = ev.target.data;
}
But this doesn't seem to work. How can I test that the full webpage is loaded 'invisibly' in the background? If "http://your_request" has cookies for example, I can check if the cookies were created, but I do not know if with this method I'll load the cookies to check if this is working at the first place.
There is no way to get http-cookies natively. But you can do this with a js-helper-function and an ExternalInterface.call. See this answer: How do I access cookies within Flash?

Frame Load Interrupted: Safari won't download a linked zip file from my Flash site

First of all I am a total noob so I apologize if this is a dumb question. I am building a Flash site that is designed to be used offline, on a private network. I have successfully linked PDF files, which Safari opens in the browser. This is fine because the file can still be saved from there. However, now I am trying to link .zip files and .mp4/.mov files and am encountering some issues.
Firefox and Safari both try to play the movie files in the browser, but I would prefer for the Open/Save dialog box to appear. As far as .zip files, Firefox prompts the dialog box, which is what I want; in Safari, a new window appears yet nothing happens. The activity window says "Frame Load Interrupted." I have researched this issue and tried tinkering with Safari settings but nothing has worked, nor am I sure it's solely a Safari issue, or if there is something I can do with the Actionscript to prompt the download dialog box. I have seen some different code options for file downloads but wasn't sure how to implement them correctly, or if that was even necessary in my case. Right now I am most familiar with URLRequest and have successfully used the two following configurations:
1)
var zipURL:URLRequest = new URLRequest("../Folder/Folder/Folder/Folder/Archive.zip");
function launchdownload(event:MouseEvent):void
{
navigateToURL(zipURL, "_blank");
}
btn_name.addEventListener(MouseEvent.CLICK,launchdownload);
2)
var request:URLRequest;
var localRef:FileReference;
btn_name.addEventListener(MouseEvent.CLICK,downloadFile);
function downloadFile (evtObj:Event):void
{
var Location:URLRequest = new URLRequest
("../Folder/Folder/Folder/Folder/Archive.zip");
navigateToURL (Location, "_new");
}
If anyone can help me to get around the Frame Load Interrupted issue and/or show me how to properly code my download button such that I can force the Open/Save dialog in all browsers, I would greatly appreciate it! Thank you so much!
You could also let ActionScript do the downloading.
If you add the following code you get a dialog box that lets you select a location to download your file and downloads it.
btn_name.addEventListener(MouseEvent.CLICK,downloadFile);
function downloadFile (evtObj:Event):void
{
var Location:URLRequest = new URLRequest();
Location.url = "http://www.example.com/image.jpg";
var fr:FileReference = new FileReference();
fr.download(request);
}