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

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()

Related

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);
}

AS3 AIR mobile urlloader progress bar

I have an app (for iOS and Android) which has the ability for users to select an image from the cameraroll or take an image using the cameraui. After selecting the image it is then uploaded to a server using urlloader and urlrequestwrapper class. This all works great but I need to display a percentage uploaded progress text/bar to the user but having real trouble finding a solution.
Thanks
Listen ProgressEvent.PROGRESS:
var loader = new URLLoader();
loader.addEventListener(ProgressEvent.PROGRESS,progressHandler);
function progressHandler(e:ProgressEvent):void {
trace(e.bytesLoaded/e.bytesTotal);
}
But notice, that your server has to support dispatching progress event for flash. Read the same problem here link

Action Script navigateToURL not working with stage3d

this simple code is not working for me :
stage.addEventListener(MouseEvent.CLICK, OnClick);
protected function OnClick(e:MouseEvent)
{
navigateToURL(new URLRequest("http://www.stackoverflow.com"), "_blank");
}
later i want url to open from flascc but that can be easily done if this works,
if this is because of security reason then is there any other way to do this? i saw in game called decision 2 their urls work even in debug version flash player + in all browsers. so there must be some other way to do this if navigateToURL dosent work.
Add the folder f:\flascc (or all disk f:) to the flash trusted locations in the security panel (you can also open this panel by the right click on any swf opened in the browser)

ActionScript: To perform non graphical operations

As I understand, ActionScript is used mostly to control graphical output on Flash websites: such as Flash based games.
However, I would like ActionScript to perform tasks not related to graphical output. Tasks, which for browser compatibility reasons, are more suitable for ActionScript: such as file upload.
Is it therefore possible to use ActionScript instead of JavaScript or to accomplish tasks that are not possible with JavaScript, such as file upload?
Are the following possible?
Run ActionScript on HTML Button Press?
Send information to ActionScript from HTML/JavaScript?
Process information without any graphical output in ActionScript?
Ouptut information from ActionScript to HTML/JavasScript?
I wish to know, if ActionScript can do what I wish.
I will have a picture of the right functions to call.
ExternalInterface is your friend:
http://help.adobe.com/nl_NL/Flash/CS5/AS3LR/flash/external/ExternalInterface.html
Some tips when using ExternalInterface:
set allowScriptAccess to "always" in the html embed code
make sure the flash has an id in your html code
Some simple examples:
1. Grab a value from javascript to flash
// actionscript 3 code
if (ExternalInterface.available)
{
var url:String = ExternalInterface.call("document.location");
// output to textfield
var t:TextField = new TextField();
addChild(t);
t.text = url;
}
2. Call a function with parameters from flash
// actionscript 3 code
if (ExternalInterface.available)
{
var result:String = "Flash rocks"
ExternalInterface.call("alert", result);
}
3. Call from javascript a function with parameters to Flash:
// javascript
window.onLoad = function()
{
document.getElementById('flashId').doSomething("javascript rocks");
}
.. and
// actionscript 3
if (ExternalInterface.available)
{
ExternalInterface.addCallback("doSomething", handleSomethingFromJavascript);// links js function to as3 function
function handleSomethingFromJavascript(value:String):void
{
// output to textfield
var t:TextField = new TextField();
addChild(t);
t.text = value;
}
}
You can do lots of stuff between flash and javascript, as you can see the intergration is almost painless! The only note is that within flash ExternalInterface is not available, so you have to test in browser. You can make a transparent Flash object using wmode="transparent". You cannot use display:none or visibility (css) because then the flash isnt executed or acts slower. To make sure it keeps running, place it position:fixed (css) on the page in a corner or something. Browsers make flash object run in a sort of sleep mode (slower) when out of screen or when inactive (ie in an inactive tab)
You can't really replace javascript with actionscript, but you can interact with it.
"Run ActionScript on HTML Button Press?" - Yes, this is possible through ExternalInterface.registerCallback. However, many actions (iirc, opening the file browser) can only be done on user interaction in flash, so you would need a flash button for that.
"Send information to ActionScript from HTML/JavaScript?" Also through externalInterface, or flashvars (but only at startup).
"Process information without any graphical output in ActionScript?" - It's a programming language, so sure. What did you have in mind?
"Ouptut information from ActionScript to HTML/JavasScript?" - yes, also through ExternalInterface.

How to control mobile softkeys from Flash application embedded in HTML

I have a flash application running Flash 9 (CS3). Application is able to control the Softkeys when this flash application is loaded in the supported mobile device. But, the application doesn't have control when the same is embedded in HTML page and browsed via supported mobile device. Any ideas how to make this work?
Thanks
Keerthi
There is no special way to receive soft key events when embedded in HTML - if the browser/OS gives the events to Flash, then you can catch them like any other key event:
var myListener = new Object();
myListener.onKeyDown = function() {
var code = Key.getCode();
if (code==ExtendedKey.SOFT1) {
trace("I got a soft key event");
}
}
Key.addListener(myListener);
However, you'll find that most phones/browsers will not give you soft key events when your SWF is embedded in HTML. This isn't part of the Flash Lite spec - strictly speaking I believe they could give you those events if they wanted to, but most phones simply use those keys for browser functions, and consume them before they get to Flash.
Note that you can check at runtime whether or not softkeys are available:
trace(System.capabilities.hasMappableSoftKeys);
trace(System.capabilities.softKeyCount);
If you use a switch statement, you can have more than one keycode associated with an action, you make a desktop version for testing too. I have done it myself.