Load media and encode with base64

I am making a program that uploads media content(images, sounds, video) to a server. My problem is that I dont understand how to load the media into my program and encode it with base64.
Flash is my target.

Currently I load images by calling the function _showFileDialog():

    private function _showFileDialog(fileType: String, textField: TextField):Void 
	var fr:FileReference = new FileReference();
	fr.addEventListener(Event.SELECT, function(e){
		var fr:FileReference = cast(e.target, FileReference);
		textField.text = fr.name;
		fr.addEventListener(Event.COMPLETE, _onLoad, false, 0, true);			
	fr.addEventListener(Event.CANCEL, function(e){
		textField.text = "Cancelled!";

private function _onLoad(E:Event):Void 
	var fr:FileReference = E.target;
	fr.removeEventListener(Event.COMPLETE, _onLoad);
	var loader:Loader = new Loader();
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onImgLoad);

private function _onImgLoad(evt:Event):Void 
	var loaderInfo:LoaderInfo = evt.target;
	loaderInfo.removeEventListener(Event.COMPLETE, _onImgLoad);
	var bmp:Bitmap = cast(loaderInfo.content, Bitmap);

QUESTION: What do I have to do to make this code load sounds and images?
and how do I encode the media to Base64?


If you want to encode to Base64, go to a ByteArray first, then here is a “BaseCode” class in Haxe that can help: https://github.com/openfl/lime/blob/6c489a23c03fba89f8632c862108343d235a15e0/lime/tools/helpers/StringHelper.hx