I think the problem here is that rating is NaN when createchildren executes (because binding doesn't execute yet) and you run into an infinite loop.
Rather than doing your work in createChildren maybe you should have a separate method that holds onto the child objects and call it from createchildren or the setter for your rating property. In that function it should see how many rating Images have been created, if the number is different from what you want you would destroy or create the appropriate number of children. You may then need to call invalidate() after that (though createchild probably is good enough to do that).
HTH,
Matt
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of superabe superabe
Sent: Monday, January 09, 2006 9:40 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Component DataBinding issue
Hi there,
I have a custom AS component that seems to generate a script time-out error when I use databinding to set one of its params.
It works fine if I hard code the param value.
Any ideas as to why this may be happening ?
TIA
- superabe
Component code(RatingCell.as)
=======================
class RatingCell extends HBox{
private var _rating:Number;
private var maxRating:Number = 5;
[Embed( "assets/images/rating_on.png" )]
private var ratingOn:String;
[Embed( "assets/images/rating_off.png" )]
private var ratingOff:String;public function RatingCell(){
}
public function get rating():Number{
return this._rating;
}
public function set rating(value:Number){
if(value > maxRating){
value = maxRating;
}
this._rating = value;
}
private function createChildren():Void{
super.createChildren();
Echo.debug("Rating Cell : createChildren");
Echo.debug("rating = " + rating);
//create active icon
for(var i:Number=0;i<rating;i++){
this.createChild(Image,undefined,{source:ratingOn}) ;
}
//create inactive icon
var startCounter:Number = rating;
while(startCounter <= maxRating){
this.createChild(Image,undefined,{source:ratingOff}) ;
startCounter++;
}
}
}Usage (Main.mxml)
================<mx:Script>
<![CDATA[
var tempRating:Number = 5;
]]>
</mx:Script><renderer:RatingCell rating="5" horizontalGap="1"/> // this works fine
<renderer:RatingCell rating="{tempRating}" horizontalGap="1"/> // this prompts script timeout error
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Web site design development | Computer software development | Software design and development |
Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.