# Custom binding

**URL:** <https://forum.kirupa.com/t/custom-binding/279890>\
**Category:** flash\
**Created:** [January 20, 2009, 1:27pm UTC](https://forum.kirupa.com/t/custom-binding/279890 "2009-01-20T13:27:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ven](https://avatars.discourse-cdn.com/v4/letter/v/f9ae1b/32.png) [@ven](https://forum.kirupa.com/u/ven)\
**Post date:** [January 20, 2009, 1:27pm UTC](https://forum.kirupa.com/t/custom-binding/279890/1 "2009-01-20T13:27:46Z")

</div>

Working on some calculating tool for a client, i needed to bind my controller components to various properties calculated by the program. It is a single stated program, so i don’t have to worry about removing the bindings at the moment. Ease of use and performance is crucial as there is a lot of variables to bind.

It’s made in Flash CS4, but i wondered if I should use the solution in other AS3 projects as well, but I am not sure how good the solution is.

Is it something to work on?  
Is there better solutions (easier to use, or better in performance)?

Examples:

BindString.as

```php

package bindings {
    
    
    /* Class */
    
    public class BindString {
        
        
        /* Private properties */
        
        private var _string:String = new String();
        private var _binds:Array = new Array();
        
        
        /* Getters and setters */
        
        public function set string(s:String):void {
            _string = s;
            for (var i:int = 0; i < _binds.length; i++) {
                _binds*();
            }
        }
        
        public function get string():String {
            return _string;
        }
        
        
        /* Methods */
        
        public function bindTo(f:Function):void {
            _binds.push(f);
        }
        
        
    }
    
}

```

Use:

```php

var myString:BindString = new BindString();

myString.bindTo(onMyStringChange);

function onMyStringChange():void {
    trace("string changed to", myString.string);
}

myString.string = "Yo";

```

Same principle goes for int, Number, Boolean, etc.
