AFAIK (I am a newb to flex) to be able to set a property in a custom
component, that property must be public. When Flex compiles the
application, mxml components are compiled into actionscript classes so
to modify the property it must be available to outside classes. Making
it private denies other objects from doing so.

Also, you are running your init method on initialize. I think you
meant for it to run on creationcomplete (This is why you are getting NaN).

I have modified your code to reflect the above:

Application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:com="*"
xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute">
        <mx:TextInput text="100" id="tiTitulo" width="200" maxChars="100"
change="descCounter.countChars(tiTitulo.length)"/>
        <com:CharCounter y="30" id="descCounter"
_maxChars="{tiTitulo.maxChars}" />
</mx:Application>


Custom Component:
<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml";
creationComplete="init()" >

<mx:Script>
        <![CDATA[

                [Bindable] private var _charNumber:Number;
                [Bindable] public var _maxChars:Number;
                
                private function init():void
                {
                        _charNumber = _maxChars;
                        this.text = this._charNumber.toString();
                }
                
                public function set maxChars(value:Number):void
                {
                        _maxChars = value;
                        trace("MAXCHARS" + _maxChars);
                }
                
                public function get maxChars():Number
                {
                        return _maxChars;
                }
                
                public function countChars(value:Number):void
                {
                        var maxChars:Number = _maxChars;
                        _charNumber = maxChars - value;
                        this.text = _charNumber.toString();
                }
        ]]>
</mx:Script>
</mx:Label>

Reply via email to