item renderer in ComboBox not consistent

View: New views
10 Messages — Rating Filter:   Alert me  

item renderer in ComboBox not consistent

by Mic-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I thought this might work --- fine until I start scrolling when it gets totally out of wack. The trace does fire occasionally while scrolling but not consistently. Appreciate some hints. TIA,

Mic.

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off">
        <mx:Script>
                <![CDATA[
  private function labelComplete():void{
          trace("Here");
          if(label1.text.substr(0,1) == "*"){
                        this.setStyle("backgroundColor", 0xe8e8e3);
                                }else{
                        this.setStyle("backgroundColor", 0xFFFFFF);
                                }
  }
                ]]>
        </mx:Script>
        <mx:Label id="label1" text="{data.cmplx_nm}"    creationComplete="labelComplete()"  />
</mx:VBox>


Re: item renderer in ComboBox not consistent

by Jeffry Houser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


 It looks like you are trying to change the background color of the
label so that you have alternating colors, is that correct?
 This won't work due to render recycling.  Renderers are re-used.  There
is not a single renderer for every item in your dataProvider.  
CreationComplete complete only runs once.

 You might try code like this on the dataChange event.  Or using
updateComplete.

 Or google it and discover the alternatingItemColors style:
http://blog.flexexamples.com/2007/08/17/alternating-row-colors-in-a-flex-list-control/

Mic wrote:

> I thought this might work --- fine until I start scrolling when it gets totally out of wack. The trace does fire occasionally while scrolling but not consistently. Appreciate some hints. TIA,
>
> Mic.
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off">
> <mx:Script>
> <![CDATA[
>   private function labelComplete():void{
>   trace("Here");
>   if(label1.text.substr(0,1) == "*"){
>                this.setStyle("backgroundColor", 0xe8e8e3);
> }else{
>                this.setStyle("backgroundColor", 0xFFFFFF);
> }
>   }
> ]]>
> </mx:Script>
>         <mx:Label id="label1" text="{data.cmplx_nm}"    creationComplete="labelComplete()"  />
> </mx:VBox>
>
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
>
>
>
>
>  

--
Jeffry Houser, Technical Entrepreneur
Adobe Community Expert: http://tinyurl.com/684b5h
http://www.twitter.com/reboog711  | Phone: 203-379-0773
--
Easy to use Interface Components for Flex Developers
http://www.flextras.com?c=104
--
http://www.theflexshow.com
http://www.jeffryhouser.com
--
Part of the DotComIt Brain Trust



ArrayCollection/Min Max Problem

by Sherif Abdou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have an array collection and I am trying to find the Min/Max of the values in groups. For Example my array collection has 100 values. I want to find the Min Value/Max Value between 1 to 26, 2 to 27, 3 to 28 , etc.... I tried to create 2 for loops in each other but for some reason during debugging/tracing it outputs wrong numbers, but if i do breakpoint then step in. I get the correct values. So the question is is there a better way than what i am doing. I am just trying to create a Stochastic formula.


     

Re: ArrayCollection/Min Max Problem

by Sam Lai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Maybe your trace statement is in the wrong place? Seeing your code
would help in solving the problem.

Another way to solve these problems is to sort the data (sub)set, then
just pull the first and last elements. Depending on what you want to
do with the data after, this may be faster.

2009/7/1 Sherif Abdou <sherif626@...>:

>
>
> I have an array collection and I am trying to find the Min/Max of the values
> in groups. For Example my array collection has 100 values. I want to find
> the Min Value/Max Value between 1 to 26, 2 to 27, 3 to 28 , etc.... I tried
> to create 2 for loops in each other but for some reason during
> debugging/tracing it outputs wrong numbers, but if i do breakpoint then step
> in. I get the correct values. So the question is is there a better way than
> what i am doing. I am just trying to create a Stochastic formula.
>
>
>
>

Re: item renderer in ComboBox not consistent

by Mic-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jeff, what this does is set the background color of the renderer's VBox and therefore the line shading to gray if the label text begins with an asterisk .... we want to highlight these paricular rows in the list. I know what you are saying about creationComplete() only running once, but I was thinking the renderer would have to redo itself on a scroll because the viewable area had changed.

--- In flexcoders@..., Jeffry Houser <jeff@...> wrote:

>
>
>  It looks like you are trying to change the background color of the
> label so that you have alternating colors, is that correct?
>  This won't work due to render recycling.  Renderers are re-used.  There
> is not a single renderer for every item in your dataProvider.  
> CreationComplete complete only runs once.
>
>  You might try code like this on the dataChange event.  Or using
> updateComplete.
>
>  Or google it and discover the alternatingItemColors style:
> http://blog.flexexamples.com/2007/08/17/alternating-row-colors-in-a-flex-list-control/
>
> Mic wrote:
> > I thought this might work --- fine until I start scrolling when it gets totally out of wack. The trace does fire occasionally while scrolling but not consistently. Appreciate some hints. TIA,
> >
> > Mic.
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off">
> > <mx:Script>
> > <![CDATA[
> >   private function labelComplete():void{
> >   trace("Here");
> >   if(label1.text.substr(0,1) == "*"){
> >                this.setStyle("backgroundColor", 0xe8e8e3);
> > }else{
> >                this.setStyle("backgroundColor", 0xFFFFFF);
> > }
> >   }
> > ]]>
> > </mx:Script>
> >         <mx:Label id="label1" text="{data.cmplx_nm}"    creationComplete="labelComplete()"  />
> > </mx:VBox>
> >
> >
> >
> > ------------------------------------
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
> >
> >
> >
> >
> >  
>
> --
> Jeffry Houser, Technical Entrepreneur
> Adobe Community Expert: http://tinyurl.com/684b5h
> http://www.twitter.com/reboog711  | Phone: 203-379-0773
> --
> Easy to use Interface Components for Flex Developers
> http://www.flextras.com?c=104
> --
> http://www.theflexshow.com
> http://www.jeffryhouser.com
> --
> Part of the DotComIt Brain Trust
>



Re: Re: item renderer in ComboBox not consistent

by Jeffry Houser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


  Use the dataChange event.  Even if the data changes, the renderer is
not re-created and creationComplete will not run again.

Mic wrote:

> Hi Jeff, what this does is set the background color of the renderer's VBox and therefore the line shading to gray if the label text begins with an asterisk .... we want to highlight these paricular rows in the list. I know what you are saying about creationComplete() only running once, but I was thinking the renderer would have to redo itself on a scroll because the viewable area had changed.
>
> --- In flexcoders@..., Jeffry Houser <jeff@...> wrote:
>  
>>  It looks like you are trying to change the background color of the
>> label so that you have alternating colors, is that correct?
>>  This won't work due to render recycling.  Renderers are re-used.  There
>> is not a single renderer for every item in your dataProvider.  
>> CreationComplete complete only runs once.
>>
>>  You might try code like this on the dataChange event.  Or using
>> updateComplete.
>>
>>  Or google it and discover the alternatingItemColors style:
>> http://blog.flexexamples.com/2007/08/17/alternating-row-colors-in-a-flex-list-control/
>>
>> Mic wrote:
>>    
>>> I thought this might work --- fine until I start scrolling when it gets totally out of wack. The trace does fire occasionally while scrolling but not consistently. Appreciate some hints. TIA,
>>>
>>> Mic.
>>>
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off">
>>> <mx:Script>
>>> <![CDATA[
>>>   private function labelComplete():void{
>>>   trace("Here");
>>>   if(label1.text.substr(0,1) == "*"){
>>>                this.setStyle("backgroundColor", 0xe8e8e3);
>>> }else{
>>>                this.setStyle("backgroundColor", 0xFFFFFF);
>>> }
>>>   }
>>> ]]>
>>> </mx:Script>
>>>         <mx:Label id="label1" text="{data.cmplx_nm}"    creationComplete="labelComplete()"  />
>>> </mx:VBox>
>>>
>>>
>>>
>>> ------------------------------------
>>>
>>> --
>>> Flexcoders Mailing List
>>> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>>> Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
>>> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
>>>
>>>
>>>
>>>
>>>  
>>>      
>> --
>> Jeffry Houser, Technical Entrepreneur
>> Adobe Community Expert: http://tinyurl.com/684b5h
>> http://www.twitter.com/reboog711  | Phone: 203-379-0773
>> --
>> Easy to use Interface Components for Flex Developers
>> http://www.flextras.com?c=104
>> --
>> http://www.theflexshow.com
>> http://www.jeffryhouser.com
>> --
>> Part of the DotComIt Brain Trust
>>
>>    
>
>
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
>
>
>
>
>  

--
Jeffry Houser, Technical Entrepreneur
Adobe Community Expert: http://tinyurl.com/684b5h
http://www.twitter.com/reboog711  | Phone: 203-379-0773
--
Easy to use Interface Components for Flex Developers
http://www.flextras.com?c=104
--
http://www.theflexshow.com
http://www.jeffryhouser.com
--
Part of the DotComIt Brain Trust


Re: item renderer in ComboBox not consistent

by valdhor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try the following as a starting point...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
     <mx:ComboBox itemRenderer="MyLabel">
         <mx:dataProvider>
              <mx:String>*United States</mx:String>
              <mx:String>Australia</mx:String>
              <mx:String>England</mx:String>
              <mx:String>*Ireland</mx:String>
              <mx:String>*Scotland</mx:String>
              <mx:String>Wales</mx:String>
         </mx:dataProvider>
     </mx:ComboBox>
</mx:Application>

MyLabel.as:
package
{
     import flash.display.Graphics;
     import mx.controls.Label;

     public class MyLabel extends Label
     {
         public function MyLabel()
         {
             super();
         }

         override public function set data(value:Object):void
         {
             if(value != null)
             {
                 super.data = value;
                 text = value as String;
             }
         }

         override protected function
updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
         {
             super.updateDisplayList(unscaledWidth, unscaledHeight);
             var g:Graphics = graphics;
             g.clear();
             if(text.substr(0,1) == "*")
             {
                 g.beginFill(0xE8E8E3);
             }
             else
             {
                 g.beginFill(0xFFFFFF);
             }
             g.drawRect(-2, -2, unscaledWidth + 4, unscaledHeight + 4);
             g.endFill();
         }
     }
}




--- In flexcoders@..., "Mic" <chigwell23@...> wrote:
>
> I thought this might work --- fine until I start scrolling when it
gets totally out of wack. The trace does fire occasionally while
scrolling but not consistently. Appreciate some hints. TIA,
>
> Mic.
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalScrollPolicy="off">

>  <mx:Script>
>   <![CDATA[
>     private function labelComplete():void{
>       trace("Here");
>       if(label1.text.substr(0,1) == "*"){
>                  this.setStyle("backgroundColor", 0xe8e8e3);
>     }else{
>                  this.setStyle("backgroundColor", 0xFFFFFF);
>     }
>     }
>   ]]>
>  </mx:Script>
>         <mx:Label id="label1" text="{data.cmplx_nm}"  
creationComplete="labelComplete()"  />
> </mx:VBox>
>


Re: ArrayCollection/Min Max Problem

by valdhor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This works for me (Although there may be a better way)...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete()">
     <mx:Script>
         <![CDATA[
             private var randomNumberArray:Array = new Array();
             private var minMaxArray:Array = new Array();
             private var currentMinMaxObject:Object;

             private function onCreationComplete():void
             {
                 for(var i:int = 0 ; i < 100 ; i++)
                 {
                     randomNumberArray.push(int(Math.random() * 100));
                 }
                 for(i = 0 ; i < 74 ; i++)
                 {
                     for(var j:int = 0 ; j < 26 ; j++)
                     {
                         currentMinMaxObject = new Object();
                         currentMinMaxObject.min = randomNumberArray[j +
i];
                         currentMinMaxObject.max = randomNumberArray[j +
i];
                         if(randomNumberArray[j + i + 1] >
currentMinMaxObject.max)
                         {
                             currentMinMaxObject.max =
randomNumberArray[j + i + 1];
                         }
                         if(randomNumberArray[j + i + 1] <
currentMinMaxObject.min)
                         {
                             currentMinMaxObject.min =
randomNumberArray[j + i + 1];
                         }
                     }
                     minMaxArray.push(currentMinMaxObject);
                 }
             }
         ]]>
     </mx:Script>
</mx:Application>
--- In flexcoders@..., Sherif Abdou <sherif626@...> wrote:
>
> I have an array collection and I am trying to find the Min/Max of the
values in groups. For Example my array collection has 100 values. I want
to find the Min Value/Max Value between 1 to 26, 2 to 27, 3 to 28 ,
etc.... I tried to create 2 for loops in each other but for some reason
during debugging/tracing it outputs wrong numbers, but if i do
breakpoint then step in. I get the correct values. So the question is is
there a better way than what i am doing. I am just trying to create a
Stochastic formula.
>


Re: item renderer in ComboBox not consistent

by Mic-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks valdhor - great solution! I had got this far but was using a textInput and its background color, and even though I had

            editable=false;
            enabled=false;

the cursor would go into the row. Not good. Question: I had to modify to

                g.beginFill(0xE8E8E3, 0.5);

otherwise the line highlight would not show through and could not tell what line was highlighted. It surprised me that a renderer was capable of doing this.

Thanks again,

Mic.


--- In flexcoders@..., "valdhor" <valdhorlists@...> wrote:

>
> Try the following as a starting point...
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> layout="absolute">
>      <mx:ComboBox itemRenderer="MyLabel">
>          <mx:dataProvider>
>               <mx:String>*United States</mx:String>
>               <mx:String>Australia</mx:String>
>               <mx:String>England</mx:String>
>               <mx:String>*Ireland</mx:String>
>               <mx:String>*Scotland</mx:String>
>               <mx:String>Wales</mx:String>
>          </mx:dataProvider>
>      </mx:ComboBox>
> </mx:Application>
>
> MyLabel.as:
> package
> {
>      import flash.display.Graphics;
>      import mx.controls.Label;
>
>      public class MyLabel extends Label
>      {
>          public function MyLabel()
>          {
>              super();
>          }
>
>          override public function set data(value:Object):void
>          {
>              if(value != null)
>              {
>                  super.data = value;
>                  text = value as String;
>              }
>          }
>
>          override protected function
> updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
>          {
>              super.updateDisplayList(unscaledWidth, unscaledHeight);
>              var g:Graphics = graphics;
>              g.clear();
>              if(text.substr(0,1) == "*")
>              {
>                  g.beginFill(0xE8E8E3);
>              }
>              else
>              {
>                  g.beginFill(0xFFFFFF);
>              }
>              g.drawRect(-2, -2, unscaledWidth + 4, unscaledHeight + 4);
>              g.endFill();
>          }
>      }
> }
>
>
>
>
> --- In flexcoders@..., "Mic" <chigwell23@> wrote:
> >
> > I thought this might work --- fine until I start scrolling when it
> gets totally out of wack. The trace does fire occasionally while
> scrolling but not consistently. Appreciate some hints. TIA,
> >
> > Mic.
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
> horizontalScrollPolicy="off">
> >  <mx:Script>
> >   <![CDATA[
> >     private function labelComplete():void{
> >       trace("Here");
> >       if(label1.text.substr(0,1) == "*"){
> >                  this.setStyle("backgroundColor", 0xe8e8e3);
> >     }else{
> >                  this.setStyle("backgroundColor", 0xFFFFFF);
> >     }
> >     }
> >   ]]>
> >  </mx:Script>
> >         <mx:Label id="label1" text="{data.cmplx_nm}"  
> creationComplete="labelComplete()"  />
> > </mx:VBox>
> >
>



Re: item renderer in ComboBox not consistent

by valdhor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Glad to be of help. A renderer can do almost anything but you have to decide whether the weight of the renderer is worth it. Depending on the amount of data, it could really slow down the display.


--- In flexcoders@..., "Mic" <chigwell23@...> wrote:

>
> Thanks valdhor - great solution! I had got this far but was using a textInput and its background color, and even though I had
>
>             editable=false;
>             enabled=false;
>
> the cursor would go into the row. Not good. Question: I had to modify to
>
>                 g.beginFill(0xE8E8E3, 0.5);
>
> otherwise the line highlight would not show through and could not tell what line was highlighted. It surprised me that a renderer was capable of doing this.
>
> Thanks again,
>
> Mic.
>
>
> --- In flexcoders@..., "valdhor" <valdhorlists@> wrote:
> >
> > Try the following as a starting point...
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> > layout="absolute">
> >      <mx:ComboBox itemRenderer="MyLabel">
> >          <mx:dataProvider>
> >               <mx:String>*United States</mx:String>
> >               <mx:String>Australia</mx:String>
> >               <mx:String>England</mx:String>
> >               <mx:String>*Ireland</mx:String>
> >               <mx:String>*Scotland</mx:String>
> >               <mx:String>Wales</mx:String>
> >          </mx:dataProvider>
> >      </mx:ComboBox>
> > </mx:Application>
> >
> > MyLabel.as:
> > package
> > {
> >      import flash.display.Graphics;
> >      import mx.controls.Label;
> >
> >      public class MyLabel extends Label
> >      {
> >          public function MyLabel()
> >          {
> >              super();
> >          }
> >
> >          override public function set data(value:Object):void
> >          {
> >              if(value != null)
> >              {
> >                  super.data = value;
> >                  text = value as String;
> >              }
> >          }
> >
> >          override protected function
> > updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
> >          {
> >              super.updateDisplayList(unscaledWidth, unscaledHeight);
> >              var g:Graphics = graphics;
> >              g.clear();
> >              if(text.substr(0,1) == "*")
> >              {
> >                  g.beginFill(0xE8E8E3);
> >              }
> >              else
> >              {
> >                  g.beginFill(0xFFFFFF);
> >              }
> >              g.drawRect(-2, -2, unscaledWidth + 4, unscaledHeight + 4);
> >              g.endFill();
> >          }
> >      }
> > }
> >
> >
> >
> >
> > --- In flexcoders@..., "Mic" <chigwell23@> wrote:
> > >
> > > I thought this might work --- fine until I start scrolling when it
> > gets totally out of wack. The trace does fire occasionally while
> > scrolling but not consistently. Appreciate some hints. TIA,
> > >
> > > Mic.
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
> > horizontalScrollPolicy="off">
> > >  <mx:Script>
> > >   <![CDATA[
> > >     private function labelComplete():void{
> > >       trace("Here");
> > >       if(label1.text.substr(0,1) == "*"){
> > >                  this.setStyle("backgroundColor", 0xe8e8e3);
> > >     }else{
> > >                  this.setStyle("backgroundColor", 0xFFFFFF);
> > >     }
> > >     }
> > >   ]]>
> > >  </mx:Script>
> > >         <mx:Label id="label1" text="{data.cmplx_nm}"  
> > creationComplete="labelComplete()"  />
> > > </mx:VBox>
> > >
> >
>