views:

353

answers:

2

Hi, I'm a newbby in Adobe AIR/Flex.

I have developed a simple Flex web app. that through 2 Php's, can connect to a DB and return an XML result of the query. I uploaded the PHP and Flex files to my internet server, and the app. works fine.

My question is:

How can I make the same app. work in Adobe AIR? In other words, I have made a new AIR project, and I copy/paste the Flex code. When I run the project, it does not work and say things like:

[RPC Fault faultString="Error #2070: Security sandbox violation: caller cannot access Stage owned by ." faultCode="Client.CouldNotDecode" faultDetail="null"] at mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:851] at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:188] at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43] at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74] at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()

So I think that in my AIR app. I cant write HTTP services. Or maybe I cant use the php file that connects to the DB, makes the query and then return an XML. How can I transform the Flex app. in an AIR app. Do I have to use the SQLConnect and that stuff? Cant I use my php's files that work well?

Thanks.

My regards.

Alan

A: 

You can write AIR applications that connect to your PHP, I use coldfusion and java so not exactly sure what differences there will be but should be none on the server side.

The AIR application will require access, or compiled with, the services-config.xml and the three files it includes. For my AIR apps it seemed like the "includes" in the servies-config.xml file did not work and I had to copy the contents of those three files into the main file.

On the compile line you will require something like: -services "C:\Blazeds\tomcat\webapps\chat\WEB-INF\flex\services-config.xml" (sorry, I develop on a windows machine), but you will require the full path to your actual services-config.xml file. That line is in my Additional Compiler Arguments with my locale option.

This also requires you to create the project with a server side option.

You might want to also look at moving the code into a separate project, and then have both your AIR and web app use that third project with the code. Then one change in the code can affect both version, of course that means everything would have to be recompiled.

PS. I found the Adobe AIR Programming Unleashed to be a good book for this information.

WayneH
A: 

Thanks for your answer WayneH.

I am trying to move my Flex application into an AIR application, because the Flex swf file was too heavy, like 1 Mb. And I do not need my app. to be online in a website. I don`t know why it is soo heavy. (Downloading 1 Mb. from your server each time you want to use your app. is not a good deal. So I plan to make the desktop version of this app).

My question is:

What do I have to exactly include in that services-config.xml ?

In my flex app. basically I have a form, a "submit" button and a datagrid. In the datagrid I can see the employees of a company, stored in an SQL database. So when you start the app, you have to retrive all the employees from the DB hosted in my server. There is an HTTPService that calls "retrive-employees.php". That file makes the query to the DB (something like "SELECT * FROM employees") and return an XML file:

<employees>

<employee>
<first-name>
Sebastian
</first-name>
</employee>

<employee>
<first-name>
Brad
</first-name>
</employee>

</employees>

Then you can choice to fill the form with a new employee and click "Send to DB". There is another HTTPService that handles that request and through the POST method, calls a php that retrives the variables posted and make the SQL query, adding the new employee to the DB.

Do you have an example of something similar to this in Adobe Air ?

I do not want to use SQLlite and that stuff. It is easier to use what I have made in flex ("add-employee.php" and "retrive-employees.php"), addapted to AIR.

Thank you again.

My regards,

Alan

Alan
http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/Since you're returning XML you might want to use "e4x" for the resultFormat because it will be parsed in to an object you can access/iterate through upon returning from the server.
Inigoesdr