1 Reply Latest reply on Jan 15, 2010 2:35 AM by jimmydubdub

    Passing JS Objects to FABridge

      I'm trying to call a function in my SWF via the bridge, passing in a class ('Person') that I've defined in both ActionScript and JavaScript. I'm fairly new to Flex, but I thought that the ability to pass complex objects was the benefit of using the FABridge over ExternalInterface. The definition of the JavaScript class is :

      function Person(forename, surname, sex){
      this.m_forename = forename;
      this.m_surname = surname;
      this.m_sex = sex;
      this.printf = function(){
      alert("General printing thing");

      The definition of the ActionScript class is :

      import mx.controls.Alert;

      public class Person
      public var m_forename:String;
      public var m_surname:String;
      public var m_sex:String;

      private const nl:String = "\n";

      public function Person(forename:String, surname:String, sex:String)
      m_forename = forename;
      m_surname = surname;
      m_sex = sex;
      public function printf():void{
      Alert.show(m_forename + nl + m_surname + nl + m_sex);


      I have a function defined in my MXML file called addPersonIntoCollection which takes a Person object, and is exposed via the FABridge. When I call the bridge method from my HTML page, like so :

      JSDrivenDataGrid.addPersonIntoCollection(new Person("Harry", "Belafonte", "Male"));

      I get an error "Error #1034: Type Coercion failed: cannot convert Object@67cd809 to Person.". Debugging the Flex app does indeed confirm that a type of Object is passed; I have tried changing the argument type on the AS addPersonIntoCollection method to Object, and tried to then coerce that Object to a Person type within the function, using both the syntax 'var _p:Person = Person(obj)' and 'var _p:Person = obj as Person', but to no avail.

      Have I misconstrued what the bridge is able to do here? Is there some way in which I can identify the JS object as being of the same type as it's AS counterpart?