Hello,
I’m having a real hard time trying to work this one out. I’m pretty new to AS3 and OOP in general, but I’m slowly progressing.
I have an uploading class that I have made that uploads mp3s to a server, that works fine, the problem I’m having is inputting information about the file into a textfield that is located on the main stage. I can’t work out how to refer to it properly, as the old AS2 method of dot syntax doesn’t work.
I had the uploader working fine when it was is in it’s own fla and not utilising external classes, and the textfield displayed exactly as I wanted. I just want to get my head round using classes and thus having cleaner, modular code.
I’ve searched all day and found some stuff that I think might help, such as displayobject and defining root and stage, but I can’t really get my head round how to do it.
Here are some code snippets that hopefully you’ll be able to make sense of…
The main fla code:
mUpload.bPlay.addEventListener(MouseEvent.CLICK, uploadFile);
function uploadFile(evt:MouseEvent):void {
var tester:Uploader = new Uploader();
}
and the Uploader.as file code:
package {
import flash.net.*;
import flash.events.*;
import flash.display.Sprite;
import flash.text.TextField;
public class Uploader extends Sprite{
private var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
private var allTypes:Array = new Array(fileTypes);
private var fileRef:FileReference = new FileReference();
public var tStatus:TextField;
public function Uploader():void {
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
try {
var success:Boolean = fileRef.browse(allTypes);
trace("Uploading...");
} catch (error:Error) {
trace("Unable to browse for files.");
}
}
private function selectHandler(event:Event):void {
var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
var allTypes:Array = new Array(fileTypes);
var request:URLRequest = new URLRequest("http://www.blahblah.com/alive/uploads/uploader.php");
try {
fileRef.upload(request);
} catch (error:Error) {
trace("Unable to upload file.");
}
}
private function completeHandler(event:Event):void {
tStatus.text = "Successfully Uploaded - " + event.target.name + " - " + event.target.size;
}
}
}
I have a textfield that i have created on the stage called tStatus within which I want to display some information once I have uploaded the file.
Any help would be greatly appreciated, for my sanity’s sake :stare: