problem in getting value of the object attribute in flex - apache-flex

i have an xml which contains 'interface' sub tag, iam converting xml to object using SampleXmlDecoder. compiler did not allow me to access the value of the 'inteface' attrible of the resultobject.
var xml:XML = event.result as XML;
var xmlDoc : XMLDocument = new XMLDocument(xml.toString());
var decoder : SimpleXMLDecoder = new SimpleXMLDecoder(true)
var resultObj : Object = decoder.decodeXML(xmlDoc);
var o:Object = new Object();
o.someprop = resultObj.maintag.item.interface;
its treating interface as keyword.
can anyone tell me the solution for this. Thanks in advance

o.someprop = resultObj.maintag.item["interface"];

Related

Convert var type to GUID type

I have a var and want to change it to System.GUID .What should I do?
var requstid = Session ["y"];
want to convert type var to GUID.
If Session contains Guid, then just cast to it:
var requstid = Session ["y"] != null ? (Guid)Session ["y"] : default(Guid);
var requestId = Guid.Parse(Session["y"]);
or
var requestId = new Guid(Session["y"]);

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

Flex - Dynamically add a property to an object based on a string value

I create a new object. My new object will always have a labelField because it has to be added to a dataProvider in a ComboBox. The problem is my next property. Each object in the dataProvider has a dataField property that has a string value [eg: 'code' or 'isoCode']. What I want to be able to do is this:
var myObject:Object = new Object; // functional
var myOtherObject:Object = new Object; // functional
myOtherObject[dataField] = "code"; // functional
myObject[labelField] = "Hi"; // functional
myObject[myOtherObject[dataField].value] = "ALL"; // not functional
Any help would be appreciated.
Try this:
var myObject:Object = new Object();
var myOtherObject:Object = new Object();
myOtherObject.dataField = "code";
myObject.labelField = "Hi";
myObject[myOtherObject.dataField] = "ALL";

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