form submission - apache-flex

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.

Related

OSMF how to get screenshot

in normal screenshot like this:
bitmapData.draw(video, new Matrix());
but how to get video object in osmf player? I've tried draw mediaPlayerSprite result in a blank image
var pictureData:BitmapData = new BitmapData(width, height);
var x:DisplayObjectTrait = _mediaPlayer.media.getTrait(org.osmf.traits.MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;
var y:Video = x.displayObject as Video;
pictureData.draw(m_container, new Matrix());
var byteArray:ByteArray = new JPEGEncoder(80).encode(pictureData);
var file:FileReference = new FileReference();
file.save(byteArray, "pic.jpeg");
To get the Bitmapdata from the video:
var videoDisplay:VideoDisplay = video.videoDisplay;
var videoObject:Video = videoDisplay.videoObject;
var bitmapData:BitmapData = new BitmapData(videoObject.videoWidth, videoObject.videoHeight, true, 0x000000);

Loading saved contents back in their places in flex air using flash builder 4.5

I have now gotten the idea of saving multiple components text into one file. But now when I open that file all the text in the file goes into the text of only one component. Here is the code,
<s:click>
var f:File = File.desktopDirectory;
f.browseForSave("Save As");
f.addEventListener(Event.SELECT, function (event:Event):void {
var stream:FileStream = new FileStream();
stream.open((event.target as File),FileMode.WRITE);
stream.writeUTFBytes(rte.htmlText);
stream.writeUTFBytes(ta.text);
stream.writeUTFBytes(rich.text);
stream.close();
});
</s:click>
</s:Button>
<s:click>
var f:File = File.desktopDirectory;
f.browseForOpen("Select file to open", []);
f.addEventListener(Event.SELECT, function (event:Event):void {
var fs:FileStream = new FileStream();
fs.open(event.target as File, FileMode.READ);
rte.htmlText = fs.readUTFBytes(fs.bytesAvailable);
ta.text = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
});
</s:click>
</s:Button>
Some suggestions?
You already read all the stream from the fs.
As soon as you execute once fs.readUTFBytes(fs.bytesAvailable); the read header/pointer will be indicating to your end of your file, so in the next line the bytesAvailable will be zero.
I suggest you use the following code:
<s:click>
var f:File = File.desktopDirectory;
f.browseForOpen("Select file to open", []);
f.addEventListener(Event.SELECT, function (event:Event):void {
var fs:FileStream = new FileStream();
fs.open(event.target as File, FileMode.READ);
var dataStr:String = fs.readUTFBytes(fs.bytesAvailable);
rte.htmlText = dataStr;
ta.text = dataStr;
// if you want only the non formatted text use: ta.text = rte.text;
fs.close();
});
</s:click>

ActionScript POST

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"));

PDF export to local using AlivePDF with flex

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");

How to Upload CSV file in flex?

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);

Resources