The OP is using a public setter function to implement his public
property, instead of a public variable, which is fine, even prefereable.

 

And the trace shows that his setter is being called, but with the
incorrect value.

 

I suspect a timing issue, but can't think of a solution.  Perhaps an
invalidate of some kind?

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of valdhor
Sent: Thursday, February 14, 2008 11:12 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Adobe SDK, why flex comps accept bind in
properties and custom comps dont?

 

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
<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
<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