I am trying to think of a way to make the binding fire after the
maxChars is set on the first component.  Calling an invalidate method
will make the component re-render.  Just thinking aloud here. 

 

Maybe you can debug this by stepping through the initializing of the
components?

 

There will be other ways to do what you want, depending on the details
of what that is.  For instance, pass a reference to the controlling
component into the custom component, and then read and set maxChars in
creationComplete.

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of danielvlopes
Sent: Friday, February 15, 2008 12:53 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Adobe SDK, why flex comps accept bind in
properties and custom comps dont?

 

Sorry Tracy, i don't know what talking about with "Perhaps an
invalidate of some kind?".... can you explain more?

Thanks.

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> 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:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of valdhor
> Sent: Thursday, February 14, 2008 11:12 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.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> 
> <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> 
> <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