3 Replies Latest reply on May 28, 2009 4:31 AM by *Prashant Shelke*

    Cast simple object to custom class

    el.watchaman

      Hi, I'm having some headaches trying to simply cast a simple Object to a custom class. Here is my code:

       

      MAIN APPLICATION:

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

      creationComplete="init();"

      >

      <mx:Script>

      <![CDATA[

      import com. elw.test.vo.SimpleClass;


       

      [Bindable]

      private var simpleClass:SimpleClass;

       


      private function init():void

      {

      var o:Object = {param:"Sample text ..."};

       


      simpleClass = SimpleClass(o);

      }

      ]]>

      </mx:Script>

      </mx:Application>

       

      With,

      SimpleClass.as:

      package com.elw.test.vo

      {

      [RemoteClass(alias='com. elw.test.vo.SimpleClass')]

       


      [Bindable]

      public class SimpleClass

      {

      public var param:String;

       


      public function SimpleClass()

      {

      }

      }

      }

       

      What I expect is that after "simpleClass = SimpleClass(o);", simpleClass is instantiated with simpleClass.param == "Sample text ...". Instead I have this error:

      Error #1034: Type Coercion failed: cannot convert Object@4842539 to com.pv.test.vo.SimpleClass.

       

      I searched a lot on Internet and tried many combinations without success. Can someone please help me? Is it even possible to do such a thing?

       

       

       

      Thanks,

      David.