Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 06:45
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  Flash Remoting with AMF (Moderators: Flash-db, Musicman, Jorge Solis, papachan, nothingGrinder)
| | |-+  VERY frustrated in TestPerson VO example - Resolved!
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: VERY frustrated in TestPerson VO example - Resolved!  (Read 3609 times)
rbw
Server what's that
*
Posts: 3


View Profile
« on: 03/27/09, 16:52 »

Hi,
I simply cannot get the TestPerson example to work!  I was excited to hear about remoting and AMFPHP but I've spent three darn days and have very little to show for it.

AMFPHP is working correctly - i got into the gateway.php page just fine, I see my services in the browser.  I've been through the general errors and fixes thread, everything appears to check out as far as I understand it.  I've got the correct URL - I was able to get the SimplePerson example working.

It seems that my objects are arriving to/from Flash and PHP, but not being translated back into the proper Person object.  When they are sent to PHP they remain as arrays, and in Actionscript, as plain Objects.
The error in savePerson:

Code:
There was a problem: Argument 1 passed to TestPerson::savePerson() must be an instance of Person, array given
and in loadData:
Code:
TypeError: Error #1034: Type Coercion failed: cannot convert Object@2665421 to vo.com.flashdb.Person.

Now in ActionScript I can change the function,
Code:
/**
* getPerson remoting callback, populates textfields
* @param  p instance of Person class
*/ 
public function getPerson_Result(p:Person):void{
name_txt.text = p.name;
age_txt.text = p.age.toString();
address_txt.text = p.address;
status_txt.text = "";
}
to take p:Object instead and this works and loads the data just fine.  It proves to me that the service is getting things from Flash - but it's not acceptable!  That gets rid of any advantages in coding, since auto-type features in my editor are then broken...

Then, when i try to take an array in TestPerson.php, it gives me this an exception:
Code:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed
at vo.com.flashdb::Main()[C:\Users\rweh\Documents\Flash\remoting2\vo\com\flashdb\Main.as:78]

So does someone have any idea what is going on??  this is totally ridiculous and I'm very close to switching to a purchased solution Sad

I'm using a current Windows server with IIS, PHP 5.2.8, latest copy of AMFPHP.  I'm using FlashDevelop to write the AS3 file, and have made only necessary changes to update the sample script and also create the GUI items which were assumed handled by Flash :/  it wouldn't compile otherwise.

Let me know if I need to give any more information for troubleshooting.
« Last Edit: 03/30/09, 15:52 by rbw » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 03/28/09, 09:33 »

If you try the working example online here: http://www.flash-db.com/Tutorials/helloAS3/helloAS3.php?page=4 , you will see that it pass typed objects along the wire (use a sniffer like Charles to test) Flash-db runs a LAMP configuration with PHP 5.2.5. Locally in my Windows machine, it works for PHP 5.2.6 over Apache. Don't know if there's some problem with IIS, but try in another server if you have the chance

Jorge
Logged

rbw
Server what's that
*
Posts: 3


View Profile
« Reply #2 on: 03/30/09, 12:58 »

Thanks for the response.  I haven't been able to try on another server, maybe I can soon, but I did copy the code again from the downloaded sample and got it to SAVE now.  But i still get the error when retrieving the PHP Person object,

Code:
TypeError: Error #1034: Type Coercion failed: cannot convert Object@2665421 to vo.com.flashdb.Person.

One thing that is difficult is that the thread on getting AMFPHP to work in IIS here, is from 2003?

Thank you.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #3 on: 03/30/09, 13:11 »

Yep ... probably the're less people working on IIS in production environments. I don't work with IIS, so I'm not sure if it's related to IIS or another thing, if you can test on another server return to this thread

Jorge
Logged

rbw
Server what's that
*
Posts: 3


View Profile
« Reply #4 on: 03/30/09, 15:03 »

OH GREAT!!  I just got it to work.  Charles was pretty useful, in showing that I had the wrong package in my PHP class (vo.com.flashdb.Person, rather than simply com.flashdb.Person), which I'd done when fussing with the first attempt.  I believe the default 'install' of AMFPHP works just fine, with the correct permissions applied in IIS.  I'm forced into IIS by the particular project I am doing, otherwise I also prefer LAMP.

I have no idea what was going wrong in the first attempt (I believe there is a line missing in the code which shows up in the downloaded sample, actually, but i haven't gone back to verify.)

Can I not attach a file here?  i have the FlashDevelop project wrapped up, but otherwise here is the code for anyone trying to get it to work.  It compiles with no errors or no warnings for me, and has been updated for AS3 with proper object and return type declarations, and a few other things.  I used the EasyButton class available here: http://www.senocular.com/flash/tutorials/as3withmxmlc/
to get button functionality.

Three files are in my project, the last has the code with my changes:
VOExample/EasyButton.as (from the site mentioned above)
VOExample/com/flashdb/Person.as (from the tutorial)
VOExample/com/flashdb/VOExample.as (modified from tutorial)
Code:
package com.flashdb{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.net.Responder;
import flash.events.MouseEvent;
import flash.events.Event;
import com.flashdb.Person;

public class VOExample extends MovieClip{
private var myService:NetConnection;

private var loadData_btn:EasyButton;
private var saveData_btn:EasyButton;
private var name_txt:TextField;
private var age_txt:TextField;
private var address_txt:TextField;
private var status_txt:TextField;


private function setupGui():void {
//setup GUI
name_txt =  new TextField();
name_txt.type = TextFieldType.INPUT;
age_txt = new TextField();
age_txt.type = TextFieldType.INPUT;
address_txt = new TextField();
address_txt.type = TextFieldType.INPUT;
status_txt = new TextField();
status_txt.type = TextFieldType.INPUT;
//text fields
name_txt.text = "name";
name_txt.x = 20;
name_txt.y = 20;
age_txt.text = "5";
age_txt.x = 20;
age_txt.y = 40;
address_txt.text = "addr";
address_txt.x = 20;
address_txt.y = 60;
status_txt.text = "status";
status_txt.y = 80;
//buttons
loadData_btn = new EasyButton("loadData");
loadData_btn.x = 110;
loadData_btn.y = 40;
saveData_btn = new EasyButton("savePerson");
saveData_btn.x = 110;
saveData_btn.y = 80;

//add GUI items
addChild(name_txt);
addChild(age_txt);
addChild(address_txt);
addChild(status_txt);
addChild(loadData_btn);
addChild(saveData_btn);
}

/**
* Constructor
*/
public function VOExample() {
setupGui();

loadData_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadData)
saveData_btn.addEventListener(MouseEvent.MOUSE_DOWN, savePerson)

Person.register();
myService = new NetConnection();
myService.objectEncoding = ObjectEncoding.AMF0;
myService.connect("http://lab-dev.eng.mobilephone.net/amfphp/gateway.php");
}
/**
* Load button callback
* @param evt Mouse Event
*/
private function loadData(evt:MouseEvent):void{
var responder:Responder = new Responder(getPerson_Result, onFault);
myService.call("TestPerson.getPerson", responder);
}
/**
* savePerson remote method callback
* @param result Boolean on success
*/
private function savePerson_Result(result:Boolean):void{
if(result){
name_txt.text = age_txt.text = address_txt.text = ""
status_txt.text = "Data saved"
} else status_txt.text = "Problem writing data"
}
/**
* getPerson remoting callback, populates textfields
* @param  p instance of Person class
*/
private function getPerson_Result(p:Person):void{
name_txt.text = p.name
age_txt.text = p.age.toString();
address_txt.text = p.address
status_txt.text = ""
}
/**
* Save button callback, minimal validation
* before send trough the wire
* @param evt MouseEvent
*/
private function savePerson(evt:MouseEvent):void{
if(name_txt.text=="" || age_txt.text=="" || address_txt.text==""){
status_txt.text = "All fields are required"

}else{
var responder:Responder = new Responder(savePerson_Result, onFault);
var p:Person = new Person(name_txt.text, parseInt(age_txt.text), address_txt.text);
myService.call("TestPerson.savePerson", responder, p);
}
}
/**
* remoting error callback
* @param   f Fault event
*/
private function onFault(f:Object):void{
status_txt.text = "There was a problem: " + f.description
}
}
}

Thanks for the pointers and efforts in AMFPHP, hopefully this helps someone else with the same issue.
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything