Announcement Announcement Module
Collapse
No announcement yet.
Pass functions as properties? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass functions as properties?

    I'm coming to ActionScript from a Java background. I find Spring to be a powerful tool, so I was quite happy to find a Spring-like tool for ActionScript. Thank you to the contributors!

    In ActionScript, we can (must) pass functions as arguments--particularly when setting up event listeners.

    Is there now--or will there be--a way to do this in Spring ActionScript? I'd love to be able to wire controllers to views right in my Spring config file. I've worked around it for now by creating an interface for event listener providers, but it'd be nice just to do it directly the way I can in ActionScript code.

    Cheers!
    Charles

  • #2
    Hi,

    I haven't tried this, but it should be possible with a FieldRetrievingFactoryObject. Since a function in ActionScript is just a variable of type Function, it should be possible to retrieve that as well.

    Code:
    <object class="org.springextensions.actionscript.ioc.factory.config.FieldRetrievingFactoryObject">
    	<property name="targetObject" ref="myInstance" />
    	<property name="targetField" value="myMethod" />
    </object>
    This is a little verbose though, we might add a shorter notation to do this. Suggestions are welcome.

    cheers,
    Christophe

    Comment


    • #3
      I'm not getting it to work.

      I can create my two objects in Spring and wire them together in code.

      XML snippet:
      Code:
        <object id="handler" class="com.example.ClickHandler" />
        <object id="button" class="mx.controls.Button">
          <property name="label" type="String" value="Push Me!" />
        </object>
      AS snippet:
      Code:
        var button:Button = applicationContext.getObject("button") as Button;
        var handler:ClickHandler = applicationContext.getObject("handler") as ClickHandler;
        button.addEventListener(MouseEvent.CLICK, handler.onClickEvent);
      And that works just fine. But the minute I add something like this to the application context XML:
      Code:
        <object id="onClickFunction" class="org.springextensions.actionscript.ioc.factory.config.FieldRetrievingFactoryObject">
          <property name="targetObject" ref="handler" />
          <property name="targetField" value="onClickEvent" />
        </object>
      I get a runtime error:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      Last edited by cwstanton; May 6th, 2009, 04:19 PM.

      Comment


      • #4
        Hi, it was indeed failing when trying to retrieve Function references. I fixed this in SVN.

        regards,
        Christophe

        Comment

        Working...
        X