i want to uplod csv file in to java from flex screen ? How can i do that ? is it possible,if it is please tell me any one ?
Use the FileReference class:
http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest(serverUrl);
req.data = csvString;
req.method = URLRequestMethod.POST;
loader.load(req);
Related
I would like to write an image in pdf. I use AlivePDF and the method is pdf.addImageStream(image,...). The image is a ByteAray and I do not know how to convert my Image object in an ByteArray. I would appreciate if you can give me a suggestion.
1.load the image:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, beginDraw);
loader.load(new URLRequest(imgURL));
2.get the bitmapData and convert to ByteArray:
private function beginDraw(event:Event):void{
var bitmap:Bitmap = loader.content as Bitmap;
var rect:Rectangle = new Rectangle(0,0,bitmap.width. bitmap.height);
var result:ByteArray = bitmap.bitmapData.getPixels(rect);
}
How to post data from a flex file to a php file? I am not able to create an action.
What you need is to create a URLRequest object where you set up your method and data to send. You then start the request with a Loader object.
var req:URLRequest = new URLRequest(yourURL);
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.yourVar = 'yourValue';
req.data = vars;
var ldr:Loader = new Loader();
ldr.load(req);
You need to create an HTTPService in order to send data to a server application like a PHP file from Flex. The data that is going to be sent could be an XML, that way in your PHP file you can parse that XML and get the information that is in it.
I use this function to transform my objects to XML and then send that XML in the HTTPService:
public function objectToXML(obj:Object, root:String):XML {
var qName:QName = new QName(root);
var xmlDocument:XMLDocument = new XMLDocument();
var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
var xml:XML = new XML(xmlDocument.toString());
return xml;
}
That way I create objects with normal properties and don't worry about how to create the XML, then when you are going to send the XML in the HTTPService you just call the method "objectToXML" on the send method of your HTTPService.
You do that like this:
var myData:Object=new Object();
myData.name="Information";
var myService:HTTPService = new HTTPService();
myService.url = "http://example.com/yourFile.php";
myService.method = "POST";
myService.contentType="application/xml";
myService.send(objectToXML(myData,"parent"));
How to specify action to button to submit a form in adobe adobe flex?
You can use the URLRequest and the Loader object.
Your function would look like this: submitForm():void {
var req:URLRequest = new URLRequest(yourURL);
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.yourVar = 'yourValue';
req.data = vars;
var ldr:Loader = new Loader();
ldr.load(req);
}
and your button would look something like this:
<mx:Button label="Submit" click="submitForm();"/>
See this page for more information.
I need to export charts and data tables to pdf file in flex application.
For this we can user AlivePDF but i need to export to local not server.
Can we export to local system prompting user to select the location to export?
Thanks in advance.
Since FP10 the FileReference Class should support this via the save() function. The code to do this in Flash Player 10 or better is shown below:
var bytes:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
file.save(bytes, "myPDF.pdf");
Try this
var pdfFile:PDF = new PDF();
var pdfByteArray:ByteArray = new ByteArray ();
pdfByteArray = pdfFile.save(Method.LOCAL);
With the latest version of AlivePDF (0.1.5 RC), you can do this:
var element:IBitmapDrawable; // Chart to export
var pdf:PDF = new UnicodePDF();
pdf.addPage();
var bitmapData:BitmapData = new BitmapData(element.width, element.height, false, 0xffffff);
try{
bitmapData.draw(element as IBitmapDrawable);
}catch(e:*)
{
throw new Error("bitmap draw failed");
}
var jpegencoder:JPEGEncoder = new JPEGEncoder(100);
var byteArray:ByteArray = jpegencoder.encode(bitmapData);
pdf.addImageStream(byteArray);
var file : FileReference = new FileReference()
file.save(pdf.save(Method.LOCAL),"my.pdf");
I need to download a file for example say, a pdf file from a url and store it in applicationsDirectory or ApplicationStorage directory , I have a code to download but its opening save dialog box to get the userinput for where to save the downloaded file.
This is the code that I am using
downloadURL.url = urlLocation;
configureListeners(file);
file.download(downloadURL);
I need to download the file with out opening any window, and file needs to be downloaded to ApplicationStorage directory.
Thanks in advance
You need the File and FileStream Classes... first load what you need as a binary URLLoader, retrieve the ByteArray, and then save it to the location you want with something like this:
var file:File = new File(File.applicationStorageDirectory.nativePath+"/myfile.jpg");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(bytes);
fileStream.close();
Where "bytes" is the bytearray you loaded...
var loader:URLLoader = new URLLoader ();
var request:URLRequest = new URLRequest ();
request.url = "http://" + "your file adress here";
loader.load(request);
loader.addEventListener(Event.COMPLETE , function (e:Event):void {
var file:File = new File(File.applicationStorageDirectory.nativePath+"/yourfile name here");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(loader.data);
fileStream.close();
});