PDA

View Full Version : class mapping with amfphp


gafoorgk
07-31-2007, 03:03 PM
hi,

i'm new to flex and amfphp. somehow both are working fine in my development machine. also class mapping is working fine.

my problem is when i tried to map a class which has reference to 2 other classes with flex it's giving me error #1034
TypeError: Error #1034: Type Coercion failed:
cannot convert Object@d8fb0e1 to com.myFlexApp.Class3

here is the php & flex classes style i am trying to use;

please note that i'm not putting _explicitType and other like-keywords. consider that it's there.

Flex
package com.myFlexApp
{
public class Class1
{
private var field11:int;
private var field12:String;
}
}

package com.myFlexApp
{
import com.myFlexApp.Class1
public class Class2
{
private var field21:int;
private var field22:String;
private var field23:Class1

function Class2() {
field23 = new Class1();
}
}
}

PHP
// com/myFlexApp/Class1.php
class Class1
{
var $field11;
var $field12;
}

// com/myFlexApp/Class2.php
require_once("Class1.php");
class Class2
{
var $field21;
var $field22;
var $field23;

function Class2() {
$field23 = new Class1();
}
}

i am creating Class2 object from a service and setting values in all fields like following;
function getTempData()
{
var $c2 = new Class2();
$c2->field21 = 1;
$c2->field22 = "test";
$c2->field23->field11 = 2;
$c2->field23->field12 = "test2";
return $c2
}

i am receiving the data in flex like following;
private function resultHandler(event:ResultEvent):void {
var c2:Class2 = Class2(event.result);
}

everything works fine except that in flex c2.field23 object is not getting populated. when i tried debugging i see the error Console window, which i pasted in the beginning.

i know that i can get the data in many other ways to flex. but i want to know whether this will work or not. i am learning flex, not under pressure to finish any application. :)

please help and thanks in advance.