PDA

View Full Version : Downloading a document



Forestknight
February 27th, 2008, 09:56 PM
Hello,
First off i want to state that i am a noob at all this, so please forgive...

What i want to do is this:
I have a button named "Application_btn"
and i want, that when this button is pressed, it begins a download of a document named "application.doc" that is on the same server.

If u need more info hehe dont hesitate to ask.

Thanks in advance

McGuffin
February 27th, 2008, 10:34 PM
package com.yourpackage {
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;

public class YourClass {

public function YourClass() {
button.addEventListener(MouseEvent.CLICK, onClick);
}

public function onClick(e:MouseEvent):void {
var link:URLRequest = new URLRequest("http://www.yoursite.com/folder/application.doc");
navigateToURL(link);
}
}
}


Obviously this isn't completely functional, as you'll need to add parts of this code in the correct locations in your existing code. But it should kick you in the right direction :)

Forestknight
February 27th, 2008, 11:21 PM
ActionScript Code:

package com.yourpackage {
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;

public class YourClass {

public function YourClass() {
button.addEventListener(MouseEvent.CLICK, onClick);
}

public function onClick(e:MouseEvent):void {
var link:URLRequest = new URLRequest("http://www.yoursite.com/folder/application.doc");
navigateToURL(link);
}
}
}





Obviously this isn't completely functional, as you'll need to add parts of this code in the correct locations in your existing code. But it should kick you in the right direction :)

Thank u very much... i stated that im new... so hopefully you all will have patience with me.. if i have more questions :)

Forestknight
February 28th, 2008, 12:07 AM
Thank u very much... i stated that im new... so hopefully you all will have patience with me.. if i have more questions :)

sorry to bother again...
I get a "Package is unexpected" error

Is there a way to do it without a package?

monkfinger
February 28th, 2008, 12:43 AM
You'll want to put that addEventListener function on the button you are trying to associate with the download function.

Basically, let's say you have a button or movieclip called "downloadButton" on the stage.

First, make sure that when you have the movieclip selected, in the properties panel the label is set to "downloadButton" this is so that actionscript can reference the specific object you want the user to interact with.

In your actions panel, add the following (this is short form):

downloadButton.addEventListener(MouseEvent.CLICK, function() {
navigateToURL(new URLRequest("http://www.yoursite.com/folder/application.doc"), "_blank");
});

the "_blank" is the target where to open the link in the browser. In HTML "A" tags, you specific the target.

Forestknight
February 28th, 2008, 06:58 AM
thank you... worked perfectly :)