You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by lj369 <jl...@vertexinc.com> on 2014/08/13 22:09:39 UTC

Who magically added that method?

Recently I noticed that there're methods on Flex classes that can be called
upon that are NOT declared nor implemented either directly by a Flex class
or indirectly by any of its parent classes.

For example, I wrote a test class called Test.as as shown below that has no
method in it and doesn't have any parent class. As soon as I make my test
class bindable and also at the same time implement
"com.adobe.cairngorm.vo.IValueObject", which is a marker interface, I
suddenly can call any of the methods declared by IEventDispatch interface,
e.g. addEventListener", on my own test class, although it doesn't have those
methods in it.

package test
{
  import com.adobe.cairngorm.vo.IValueObject;

  [Bindable]
  public class Test implements IValueObject
  {
    public function Test()
    {
        addEventListener("test"), null);
    }
  }
}

I wonder how Flex does this trick.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Who-magically-added-that-method-tp7643.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Who magically added that method?

Posted by Alex Harui <ah...@adobe.com>.
AIUI, the link is purely about [Bindable].  When the compiler sees
[Bindable] used on a class that does not implement IEventDispatcher or
inherits from EventDispatcher, it injects an IEventDispatcher
implementation into the class definition.

-Alex

On 8/13/14 1:59 PM, "lj369" <jl...@vertexinc.com> wrote:

>Thanks Alex. I was kinda wondering how the compiler knows that a bindable
>class that implements the cairngorm's IValueObject interface needs to have
>all the IEventDispatcher's methods added to it. I was speculating there's
>got to be a place, e.g. a configuration file of some sort, that the
>compiler
>looks to in order to make it happen. I dug around and checked the
>"catalog.xml" in cairngorm.swc but didn't see anything that would link the
>two. Where exactly is the link between IValueObject and IEventDispatcher?
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/Who-magically-added-that-me
>thod-tp7643p7645.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.


Re: Who magically added that method?

Posted by lj369 <jl...@vertexinc.com>.
Thanks Alex. I was kinda wondering how the compiler knows that a bindable
class that implements the cairngorm's IValueObject interface needs to have
all the IEventDispatcher's methods added to it. I was speculating there's
got to be a place, e.g. a configuration file of some sort, that the compiler
looks to in order to make it happen. I dug around and checked the
"catalog.xml" in cairngorm.swc but didn't see anything that would link the
two. Where exactly is the link between IValueObject and IEventDispatcher?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Who-magically-added-that-method-tp7643p7645.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Who magically added that method?

Posted by Alex Harui <ah...@adobe.com>.
The compiler did it.
Sent via the PANTECH Discover, an AT&T 4G LTE smartphone.

lj369 <jl...@vertexinc.com> wrote:


Recently I noticed that there're methods on Flex classes that can be called
upon that are NOT declared nor implemented either directly by a Flex class
or indirectly by any of its parent classes.

For example, I wrote a test class called Test.as as shown below that has no
method in it and doesn't have any parent class. As soon as I make my test
class bindable and also at the same time implement
"com.adobe.cairngorm.vo.IValueObject", which is a marker interface, I
suddenly can call any of the methods declared by IEventDispatch interface,
e.g. addEventListener", on my own test class, although it doesn't have those
methods in it.

package test
{
  import com.adobe.cairngorm.vo.IValueObject;

  [Bindable]
  public class Test implements IValueObject
  {
    public function Test()
    {
        addEventListener("test"), null);
    }
  }
}

I wonder how Flex does this trick.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Who-magically-added-that-method-tp7643.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.