Using Objectproxy ( as an alternative to binding) in SystemMediator and Vo

vishwas.gagrani's Avatar

vishwas.gagrani

24 Dec, 2012 06:23 AM

hi!
Since i am having number of components ( checkbox,optionbox,textinput ), in number of views, it seems a hectic process for me to do something without "binding". And unfortunately, i am not able to find any solution for using binding in Flash. .

However i got some suggestions over using "ObjectProxy" to watch out the changes in an object ( say a Vo that represents particular view ) here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/...

So here is a simple plan ( image attached) i am going to use. Do you see any problem, in the way i am going to use ObjectProxy.

In the attached image, SystemMediator is just an upper level control, that would use objectproxy, to watch the changes in Vo. It responds as per the validation functions there.
A similar validation with objectproxy can be done in "Vo". So the values inside the VO will change only when the validation is passed.

PS: Why i wanna use something like "binding" or "watcher" is because, of the huge number of components. Thinking about controlling so many number of eventdispatchers is like a nightmare for me.

Vishwas

  1. Support Staff 1 Posted by Ondina D.F. on 24 Dec, 2012 03:43 PM

    Ondina D.F.'s Avatar

    Hi Vishwas,

    I’m busy with travel preparations, so I don’t have time to answer your question properly, but I’ve notified Shaun about it.

    Ondina

  2. Support Staff 2 Posted by Shaun Smith on 27 Dec, 2012 04:19 PM

    Shaun Smith's Avatar

    Hi Vishwas,

    ObjectProxy provides one way to do "binding", but you could still just do it the normal way:

    [Bindable]
    Class VO
        public var prop1:String;
        public var prop2:String;
    

    Binding is not specific to Flex (it is just that MXML is the most convenient way to use binding). Also, MXML isn't even specific to Flex - you can use it lay out ActionScript views (but that's a whole other discussion).

    Binding is simply an event driven mechanism for updating values (apologies if you know all of this already). The long-hand form of the VO psuedocode above is as follows:

    Class VO extends EventDispatcher
    
        [Bindable("prop1Change")]
        public function get prop1():String
            return _prop1;
    
        public function set prop1(value:String):void
            if (_prop1 != value)
                _prop1 = value;
                dispatchEvent(new Event("prop1Change"))
    

    With MXML you are then able to bind directly to such a property:

    <Label text="{vo.prop1}" />
    

    With plain ActionScript you'd need to use BindingUtil:

    BindingUtils.bindProperty(myLabel, 'text', vo, ['prop1']);
    

    Hope that helps, or provides some clues!

  3. 3 Posted by vishwas.gagrani on 27 Dec, 2012 04:27 PM

    vishwas.gagrani's Avatar

    Thanks Shaun.
    I think, i too agree with you. Binding should not be specific to flex.
    I did everything to make binding work in Flash... but failed.
    http://stackoverflow.com/questions/13904382/trying-to-use-bindingut...

    I even tried "bindage-tools" ( which seems an extended form of binding-tools )
    http://stackoverflow.com/questions/14009308/bindage-tools-doesnot-r...
    That too doesnot seem to work in Flash.

    I also, checked ON the "swc" ( The similar bug that causes "Robotlegs" metatags not to work in Flash). But that too didnot work

    Anyways.. i am going to look into your explanation. I am sure, i will get some clues as always. Thanks for response and help.

    Vishwas

  4. vishwas.gagrani closed this discussion on 27 Dec, 2012 04:27 PM.

  5. Shaun Smith re-opened this discussion on 27 Dec, 2012 04:38 PM

  6. Support Staff 4 Posted by Shaun Smith on 27 Dec, 2012 04:38 PM

    Shaun Smith's Avatar

    Are you compiling with Flash Pro (the Flash IDE), or are you using FlashBuilder/FDT/IntelliJ/FlashDevelop to compile plain ActionScript projects? I doubt binding will work with the Flash Pro compiler (which is, sadly, different from the compiler provided by the Flex SDK, and not entirely compatible).

  7. Support Staff 5 Posted by Shaun Smith on 27 Dec, 2012 05:02 PM

    Shaun Smith's Avatar

    Regarding your first SO question, did you try the long-hand binding form? The short-hand version requires the compiler to rewrite the class definition.

  8. 6 Posted by vishwas.gagrani on 27 Dec, 2012 06:37 PM

    vishwas.gagrani's Avatar

    amm... The code i am testing is so simple, that i don't see any scope of using long-hand binding form.

     import mx.binding.utils.*;
     [Bindable]
     var myValue:int = 0;
     var cw:ChangeWatcher = BindingUtils.bindSetter(myValueChanged, this, "myValue");
      addEventListener( Event.ENTER_FRAME , ef);
    
     function ef(e:Event):void
       {
    trace("hello",getTimer());
    myValue = getTimer();
     }
    
     function myValueChanged(o:Object):void
     {
        trace("myValue: " + myValue.toString());
     }
    

    I would be glad to know, if there is some long-handed version for this code. And ultimately can make it work . :)

    PS: And yes, it's Flash Pro compiler i am using.

  9. Support Staff 7 Posted by Shaun Smith on 27 Dec, 2012 08:48 PM

    Shaun Smith's Avatar
  10. 8 Posted by vishwas.gagrani on 28 Dec, 2012 07:13 AM

    vishwas.gagrani's Avatar

    That was wonderful. Thanks tonnes! :)

  11. vishwas.gagrani closed this discussion on 28 Dec, 2012 07:13 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac