| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Apr 2005
Posts: 32
|
Hello,
I have an .as Class file that have a few event handlers in it.... I'm using this class to upload files to my server... here is the code. Code:
package as3
{
import flash.display.Sprite;
import flash.events.*;
import flash.net.FileReference;
import flash.net.URLRequest;
public class FileUpload extends Sprite {
private var uploadURL:URLRequest;
private var file:FileReference;
public function FileUpload() {
uploadURL = new URLRequest();
uploadURL.url = "http://www.mywebsite.com/upload.php";
file = new FileReference();
file.addEventListener(Event.SELECT, selectHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
}
public function FileBrowse():void
{
file.browse();
}
private function selectHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
file.upload(uploadURL);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
private function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
}
}
For example.. I'm trying to change the currentState of my appliction using the selectHandler above. in my main application all I have to do is call "this.currentState="state"; and it works... but I don't know how to do this from within my class file. Thank you. |
|
|
|
|
|
#2 |
|
lala
Join Date: Feb 2002
Location: on the road
Posts: 2,859
|
you need to add a listener to your class and dispatch an event you listen to somewhere else
|
|
|
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Jan 2007
Posts: 3
|
if you run into the Error #2038. AND you're using FireFox you might want to read this important thread:
http://tech.groups.yahoo.com/group/f.../message/55890 it says Firefox has problems handing the FileReference over to the browser. I can't seem to get FileReference to work in FireFox 1.5. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pre-loading multiple files - SOLUTION | Prpl_Ppl_Etr | ActionScript 2.0 | 2 | 07-29-2008 07:39 PM |
| Using the mx.util.Delegate class within your classes! | madgett | ActionScript 2.0 | 3 | 09-03-2007 12:11 AM |
| using a Class file to return an XML value | dan_d | ActionScript 2.0 | 3 | 03-26-2006 06:56 PM |
| class and event dispatcher. | Skindc | ActionScript 2.0 | 2 | 10-07-2005 04:04 PM |
| card game: designing Deck class and good OOP? | pigpen | Gaming and Game Development | 1 | 11-26-2002 12:41 PM |